From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../tests/tools/wave/www/lib/davidshimjs/LICENSE | 14 + .../tests/tools/wave/www/lib/davidshimjs/qrcode.js | 1533 ++++++++++++++++++++ .../tests/tools/wave/www/lib/jszip.min.js | 15 + .../tests/tools/wave/www/lib/keycodes.js | 88 ++ .../tests/tools/wave/www/lib/qrcode.js | 1533 ++++++++++++++++++++ .../tests/tools/wave/www/lib/query-parser.js | 12 + .../tests/tools/wave/www/lib/screen-console.js | 16 + .../web-platform/tests/tools/wave/www/lib/ui.js | 100 ++ .../web-platform/tests/tools/wave/www/lib/utils.js | 57 + .../tests/tools/wave/www/lib/wave-service.js | 866 +++++++++++ 10 files changed, 4234 insertions(+) create mode 100644 testing/web-platform/tests/tools/wave/www/lib/davidshimjs/LICENSE create mode 100644 testing/web-platform/tests/tools/wave/www/lib/davidshimjs/qrcode.js create mode 100644 testing/web-platform/tests/tools/wave/www/lib/jszip.min.js create mode 100644 testing/web-platform/tests/tools/wave/www/lib/keycodes.js create mode 100644 testing/web-platform/tests/tools/wave/www/lib/qrcode.js create mode 100644 testing/web-platform/tests/tools/wave/www/lib/query-parser.js create mode 100644 testing/web-platform/tests/tools/wave/www/lib/screen-console.js create mode 100644 testing/web-platform/tests/tools/wave/www/lib/ui.js create mode 100644 testing/web-platform/tests/tools/wave/www/lib/utils.js create mode 100644 testing/web-platform/tests/tools/wave/www/lib/wave-service.js (limited to 'testing/web-platform/tests/tools/wave/www/lib') diff --git a/testing/web-platform/tests/tools/wave/www/lib/davidshimjs/LICENSE b/testing/web-platform/tests/tools/wave/www/lib/davidshimjs/LICENSE new file mode 100644 index 0000000000..93c33233fa --- /dev/null +++ b/testing/web-platform/tests/tools/wave/www/lib/davidshimjs/LICENSE @@ -0,0 +1,14 @@ +The MIT License (MIT) +--------------------- +Copyright (c) 2012 davidshimjs + +Permission is hereby granted, free of charge, +to any person obtaining a copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/testing/web-platform/tests/tools/wave/www/lib/davidshimjs/qrcode.js b/testing/web-platform/tests/tools/wave/www/lib/davidshimjs/qrcode.js new file mode 100644 index 0000000000..45e5d7b974 --- /dev/null +++ b/testing/web-platform/tests/tools/wave/www/lib/davidshimjs/qrcode.js @@ -0,0 +1,1533 @@ +/** + * @fileoverview + * - Using the 'QRCode for Javascript library' + * - Fixed dataset of 'QRCode for Javascript library' for support full-spec. + * - this library has no dependencies. + * + * @author davidshimjs + * @see http://www.d-project.com/ + * @see http://jeromeetienne.github.com/jquery-qrcode/ + */ +var QRCode +;(function () { + // --------------------------------------------------------------------- + // QRCode for JavaScript + // + // Copyright (c) 2009 Kazuhiko Arase + // + // URL: http://www.d-project.com/ + // + // Licensed under the MIT license: + // http://www.opensource.org/licenses/mit-license.php + // + // The word "QR Code" is registered trademark of + // DENSO WAVE INCORPORATED + // http://www.denso-wave.com/qrcode/faqpatent-e.html + // + // --------------------------------------------------------------------- + function QR8bitByte (data) { + this.mode = QRMode.MODE_8BIT_BYTE + this.data = data + this.parsedData = [] + + // Added to support UTF-8 Characters + for (var i = 0, l = this.data.length; i < l; i++) { + var byteArray = [] + var code = this.data.charCodeAt(i) + + if (code > 0x10000) { + byteArray[0] = 0xf0 | ((code & 0x1c0000) >>> 18) + byteArray[1] = 0x80 | ((code & 0x3f000) >>> 12) + byteArray[2] = 0x80 | ((code & 0xfc0) >>> 6) + byteArray[3] = 0x80 | (code & 0x3f) + } else if (code > 0x800) { + byteArray[0] = 0xe0 | ((code & 0xf000) >>> 12) + byteArray[1] = 0x80 | ((code & 0xfc0) >>> 6) + byteArray[2] = 0x80 | (code & 0x3f) + } else if (code > 0x80) { + byteArray[0] = 0xc0 | ((code & 0x7c0) >>> 6) + byteArray[1] = 0x80 | (code & 0x3f) + } else { + byteArray[0] = code + } + + this.parsedData.push(byteArray) + } + + this.parsedData = Array.prototype.concat.apply([], this.parsedData) + + if (this.parsedData.length != this.data.length) { + this.parsedData.unshift(191) + this.parsedData.unshift(187) + this.parsedData.unshift(239) + } + } + + QR8bitByte.prototype = { + getLength: function (buffer) { + return this.parsedData.length + }, + write: function (buffer) { + for (var i = 0, l = this.parsedData.length; i < l; i++) { + buffer.put(this.parsedData[i], 8) + } + } + } + + function QRCodeModel (typeNumber, errorCorrectLevel) { + this.typeNumber = typeNumber + this.errorCorrectLevel = errorCorrectLevel + this.modules = null + this.moduleCount = 0 + this.dataCache = null + this.dataList = [] + } + + QRCodeModel.prototype = { + addData: function (data) { + var newData = new QR8bitByte(data) + this.dataList.push(newData) + this.dataCache = null + }, + isDark: function (row, col) { + if ( + row < 0 || + this.moduleCount <= row || + col < 0 || + this.moduleCount <= col + ) { + throw new Error(row + ',' + col) + } + return this.modules[row][col] + }, + getModuleCount: function () { + return this.moduleCount + }, + make: function () { + this.makeImpl(false, this.getBestMaskPattern()) + }, + makeImpl: function (test, maskPattern) { + this.moduleCount = this.typeNumber * 4 + 17 + this.modules = new Array(this.moduleCount) + for (var row = 0; row < this.moduleCount; row++) { + this.modules[row] = new Array(this.moduleCount) + for (var col = 0; col < this.moduleCount; col++) { + this.modules[row][col] = null + } + } + this.setupPositionProbePattern(0, 0) + this.setupPositionProbePattern(this.moduleCount - 7, 0) + this.setupPositionProbePattern(0, this.moduleCount - 7) + this.setupPositionAdjustPattern() + this.setupTimingPattern() + this.setupTypeInfo(test, maskPattern) + if (this.typeNumber >= 7) { + this.setupTypeNumber(test) + } + if (this.dataCache == null) { + this.dataCache = QRCodeModel.createData( + this.typeNumber, + this.errorCorrectLevel, + this.dataList + ) + } + this.mapData(this.dataCache, maskPattern) + }, + setupPositionProbePattern: function (row, col) { + for (var r = -1; r <= 7; r++) { + if (row + r <= -1 || this.moduleCount <= row + r) continue + for (var c = -1; c <= 7; c++) { + if (col + c <= -1 || this.moduleCount <= col + c) continue + if ( + (r >= 0 && r <= 6 && (c == 0 || c == 6)) || + (c >= 0 && c <= 6 && (r == 0 || r == 6)) || + (r >= 2 && r <= 4 && c >= 2 && c <= 4) + ) { + this.modules[row + r][col + c] = true + } else { + this.modules[row + r][col + c] = false + } + } + } + }, + getBestMaskPattern: function () { + var minLostPoint = 0 + var pattern = 0 + for (var i = 0; i < 8; i++) { + this.makeImpl(true, i) + var lostPoint = QRUtil.getLostPoint(this) + if (i == 0 || minLostPoint > lostPoint) { + minLostPoint = lostPoint + pattern = i + } + } + return pattern + }, + createMovieClip: function (target_mc, instance_name, depth) { + var qr_mc = target_mc.createEmptyMovieClip(instance_name, depth) + var cs = 1 + this.make() + for (var row = 0; row < this.modules.length; row++) { + var y = row * cs + for (var col = 0; col < this.modules[row].length; col++) { + var x = col * cs + var dark = this.modules[row][col] + if (dark) { + qr_mc.beginFill(0, 100) + qr_mc.moveTo(x, y) + qr_mc.lineTo(x + cs, y) + qr_mc.lineTo(x + cs, y + cs) + qr_mc.lineTo(x, y + cs) + qr_mc.endFill() + } + } + } + return qr_mc + }, + setupTimingPattern: function () { + for (var r = 8; r < this.moduleCount - 8; r++) { + if (this.modules[r][6] != null) { + continue + } + this.modules[r][6] = r % 2 == 0 + } + for (var c = 8; c < this.moduleCount - 8; c++) { + if (this.modules[6][c] != null) { + continue + } + this.modules[6][c] = c % 2 == 0 + } + }, + setupPositionAdjustPattern: function () { + var pos = QRUtil.getPatternPosition(this.typeNumber) + for (var i = 0; i < pos.length; i++) { + for (var j = 0; j < pos.length; j++) { + var row = pos[i] + var col = pos[j] + if (this.modules[row][col] != null) { + continue + } + for (var r = -2; r <= 2; r++) { + for (var c = -2; c <= 2; c++) { + if ( + r == -2 || + r == 2 || + c == -2 || + c == 2 || + (r == 0 && c == 0) + ) { + this.modules[row + r][col + c] = true + } else { + this.modules[row + r][col + c] = false + } + } + } + } + } + }, + setupTypeNumber: function (test) { + var bits = QRUtil.getBCHTypeNumber(this.typeNumber) + for (var i = 0; i < 18; i++) { + var mod = !test && ((bits >> i) & 1) == 1 + this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod + } + for (var i = 0; i < 18; i++) { + var mod = !test && ((bits >> i) & 1) == 1 + this.modules[i % 3 + this.moduleCount - 8 - 3][Math.floor(i / 3)] = mod + } + }, + setupTypeInfo: function (test, maskPattern) { + var data = (this.errorCorrectLevel << 3) | maskPattern + var bits = QRUtil.getBCHTypeInfo(data) + for (var i = 0; i < 15; i++) { + var mod = !test && ((bits >> i) & 1) == 1 + if (i < 6) { + this.modules[i][8] = mod + } else if (i < 8) { + this.modules[i + 1][8] = mod + } else { + this.modules[this.moduleCount - 15 + i][8] = mod + } + } + for (var i = 0; i < 15; i++) { + var mod = !test && ((bits >> i) & 1) == 1 + if (i < 8) { + this.modules[8][this.moduleCount - i - 1] = mod + } else if (i < 9) { + this.modules[8][15 - i - 1 + 1] = mod + } else { + this.modules[8][15 - i - 1] = mod + } + } + this.modules[this.moduleCount - 8][8] = !test + }, + mapData: function (data, maskPattern) { + var inc = -1 + var row = this.moduleCount - 1 + var bitIndex = 7 + var byteIndex = 0 + for (var col = this.moduleCount - 1; col > 0; col -= 2) { + if (col == 6) col-- + while (true) { + for (var c = 0; c < 2; c++) { + if (this.modules[row][col - c] == null) { + var dark = false + if (byteIndex < data.length) { + dark = ((data[byteIndex] >>> bitIndex) & 1) == 1 + } + var mask = QRUtil.getMask(maskPattern, row, col - c) + if (mask) { + dark = !dark + } + this.modules[row][col - c] = dark + bitIndex-- + if (bitIndex == -1) { + byteIndex++ + bitIndex = 7 + } + } + } + row += inc + if (row < 0 || this.moduleCount <= row) { + row -= inc + inc = -inc + break + } + } + } + } + } + QRCodeModel.PAD0 = 0xec + QRCodeModel.PAD1 = 0x11 + QRCodeModel.createData = function (typeNumber, errorCorrectLevel, dataList) { + var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel) + var buffer = new QRBitBuffer() + for (var i = 0; i < dataList.length; i++) { + var data = dataList[i] + buffer.put(data.mode, 4) + buffer.put( + data.getLength(), + QRUtil.getLengthInBits(data.mode, typeNumber) + ) + data.write(buffer) + } + var totalDataCount = 0 + for (var i = 0; i < rsBlocks.length; i++) { + totalDataCount += rsBlocks[i].dataCount + } + if (buffer.getLengthInBits() > totalDataCount * 8) { + throw new Error( + 'code length overflow. (' + + buffer.getLengthInBits() + + '>' + + totalDataCount * 8 + + ')' + ) + } + if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) { + buffer.put(0, 4) + } + while (buffer.getLengthInBits() % 8 != 0) { + buffer.putBit(false) + } + while (true) { + if (buffer.getLengthInBits() >= totalDataCount * 8) { + break + } + buffer.put(QRCodeModel.PAD0, 8) + if (buffer.getLengthInBits() >= totalDataCount * 8) { + break + } + buffer.put(QRCodeModel.PAD1, 8) + } + return QRCodeModel.createBytes(buffer, rsBlocks) + } + QRCodeModel.createBytes = function (buffer, rsBlocks) { + var offset = 0 + var maxDcCount = 0 + var maxEcCount = 0 + var dcdata = new Array(rsBlocks.length) + var ecdata = new Array(rsBlocks.length) + for (var r = 0; r < rsBlocks.length; r++) { + var dcCount = rsBlocks[r].dataCount + var ecCount = rsBlocks[r].totalCount - dcCount + maxDcCount = Math.max(maxDcCount, dcCount) + maxEcCount = Math.max(maxEcCount, ecCount) + dcdata[r] = new Array(dcCount) + for (var i = 0; i < dcdata[r].length; i++) { + dcdata[r][i] = 0xff & buffer.buffer[i + offset] + } + offset += dcCount + var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount) + var rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1) + var modPoly = rawPoly.mod(rsPoly) + ecdata[r] = new Array(rsPoly.getLength() - 1) + for (var i = 0; i < ecdata[r].length; i++) { + var modIndex = i + modPoly.getLength() - ecdata[r].length + ecdata[r][i] = modIndex >= 0 ? modPoly.get(modIndex) : 0 + } + } + var totalCodeCount = 0 + for (var i = 0; i < rsBlocks.length; i++) { + totalCodeCount += rsBlocks[i].totalCount + } + var data = new Array(totalCodeCount) + var index = 0 + for (var i = 0; i < maxDcCount; i++) { + for (var r = 0; r < rsBlocks.length; r++) { + if (i < dcdata[r].length) { + data[index++] = dcdata[r][i] + } + } + } + for (var i = 0; i < maxEcCount; i++) { + for (var r = 0; r < rsBlocks.length; r++) { + if (i < ecdata[r].length) { + data[index++] = ecdata[r][i] + } + } + } + return data + } + var QRMode = { + MODE_NUMBER: 1 << 0, + MODE_ALPHA_NUM: 1 << 1, + MODE_8BIT_BYTE: 1 << 2, + MODE_KANJI: 1 << 3 + } + var QRErrorCorrectLevel = { L: 1, M: 0, Q: 3, H: 2 } + var QRMaskPattern = { + PATTERN000: 0, + PATTERN001: 1, + PATTERN010: 2, + PATTERN011: 3, + PATTERN100: 4, + PATTERN101: 5, + PATTERN110: 6, + PATTERN111: 7 + } + var QRUtil = { + PATTERN_POSITION_TABLE: [ + [], + [6, 18], + [6, 22], + [6, 26], + [6, 30], + [6, 34], + [6, 22, 38], + [6, 24, 42], + [6, 26, 46], + [6, 28, 50], + [6, 30, 54], + [6, 32, 58], + [6, 34, 62], + [6, 26, 46, 66], + [6, 26, 48, 70], + [6, 26, 50, 74], + [6, 30, 54, 78], + [6, 30, 56, 82], + [6, 30, 58, 86], + [6, 34, 62, 90], + [6, 28, 50, 72, 94], + [6, 26, 50, 74, 98], + [6, 30, 54, 78, 102], + [6, 28, 54, 80, 106], + [6, 32, 58, 84, 110], + [6, 30, 58, 86, 114], + [6, 34, 62, 90, 118], + [6, 26, 50, 74, 98, 122], + [6, 30, 54, 78, 102, 126], + [6, 26, 52, 78, 104, 130], + [6, 30, 56, 82, 108, 134], + [6, 34, 60, 86, 112, 138], + [6, 30, 58, 86, 114, 142], + [6, 34, 62, 90, 118, 146], + [6, 30, 54, 78, 102, 126, 150], + [6, 24, 50, 76, 102, 128, 154], + [6, 28, 54, 80, 106, 132, 158], + [6, 32, 58, 84, 110, 136, 162], + [6, 26, 54, 82, 110, 138, 166], + [6, 30, 58, 86, 114, 142, 170] + ], + G15: + (1 << 10) | + (1 << 8) | + (1 << 5) | + (1 << 4) | + (1 << 2) | + (1 << 1) | + (1 << 0), + G18: + (1 << 12) | + (1 << 11) | + (1 << 10) | + (1 << 9) | + (1 << 8) | + (1 << 5) | + (1 << 2) | + (1 << 0), + G15_MASK: (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1), + getBCHTypeInfo: function (data) { + var d = data << 10 + while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) { + d ^= + QRUtil.G15 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15)) + } + return ((data << 10) | d) ^ QRUtil.G15_MASK + }, + getBCHTypeNumber: function (data) { + var d = data << 12 + while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) { + d ^= + QRUtil.G18 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18)) + } + return (data << 12) | d + }, + getBCHDigit: function (data) { + var digit = 0 + while (data != 0) { + digit++ + data >>>= 1 + } + return digit + }, + getPatternPosition: function (typeNumber) { + return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1] + }, + getMask: function (maskPattern, i, j) { + switch (maskPattern) { + case QRMaskPattern.PATTERN000: + return (i + j) % 2 == 0 + case QRMaskPattern.PATTERN001: + return i % 2 == 0 + case QRMaskPattern.PATTERN010: + return j % 3 == 0 + case QRMaskPattern.PATTERN011: + return (i + j) % 3 == 0 + case QRMaskPattern.PATTERN100: + return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0 + case QRMaskPattern.PATTERN101: + return (i * j) % 2 + (i * j) % 3 == 0 + case QRMaskPattern.PATTERN110: + return ((i * j) % 2 + (i * j) % 3) % 2 == 0 + case QRMaskPattern.PATTERN111: + return ((i * j) % 3 + (i + j) % 2) % 2 == 0 + default: + throw new Error('bad maskPattern:' + maskPattern) + } + }, + getErrorCorrectPolynomial: function (errorCorrectLength) { + var a = new QRPolynomial([1], 0) + for (var i = 0; i < errorCorrectLength; i++) { + a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0)) + } + return a + }, + getLengthInBits: function (mode, type) { + if (type >= 1 && type < 10) { + switch (mode) { + case QRMode.MODE_NUMBER: + return 10 + case QRMode.MODE_ALPHA_NUM: + return 9 + case QRMode.MODE_8BIT_BYTE: + return 8 + case QRMode.MODE_KANJI: + return 8 + default: + throw new Error('mode:' + mode) + } + } else if (type < 27) { + switch (mode) { + case QRMode.MODE_NUMBER: + return 12 + case QRMode.MODE_ALPHA_NUM: + return 11 + case QRMode.MODE_8BIT_BYTE: + return 16 + case QRMode.MODE_KANJI: + return 10 + default: + throw new Error('mode:' + mode) + } + } else if (type < 41) { + switch (mode) { + case QRMode.MODE_NUMBER: + return 14 + case QRMode.MODE_ALPHA_NUM: + return 13 + case QRMode.MODE_8BIT_BYTE: + return 16 + case QRMode.MODE_KANJI: + return 12 + default: + throw new Error('mode:' + mode) + } + } else { + throw new Error('type:' + type) + } + }, + getLostPoint: function (qrCode) { + var moduleCount = qrCode.getModuleCount() + var lostPoint = 0 + for (var row = 0; row < moduleCount; row++) { + for (var col = 0; col < moduleCount; col++) { + var sameCount = 0 + var dark = qrCode.isDark(row, col) + for (var r = -1; r <= 1; r++) { + if (row + r < 0 || moduleCount <= row + r) { + continue + } + for (var c = -1; c <= 1; c++) { + if (col + c < 0 || moduleCount <= col + c) { + continue + } + if (r == 0 && c == 0) { + continue + } + if (dark == qrCode.isDark(row + r, col + c)) { + sameCount++ + } + } + } + if (sameCount > 5) { + lostPoint += 3 + sameCount - 5 + } + } + } + for (var row = 0; row < moduleCount - 1; row++) { + for (var col = 0; col < moduleCount - 1; col++) { + var count = 0 + if (qrCode.isDark(row, col)) count++ + if (qrCode.isDark(row + 1, col)) count++ + if (qrCode.isDark(row, col + 1)) count++ + if (qrCode.isDark(row + 1, col + 1)) count++ + if (count == 0 || count == 4) { + lostPoint += 3 + } + } + } + for (var row = 0; row < moduleCount; row++) { + for (var col = 0; col < moduleCount - 6; col++) { + if ( + qrCode.isDark(row, col) && + !qrCode.isDark(row, col + 1) && + qrCode.isDark(row, col + 2) && + qrCode.isDark(row, col + 3) && + qrCode.isDark(row, col + 4) && + !qrCode.isDark(row, col + 5) && + qrCode.isDark(row, col + 6) + ) { + lostPoint += 40 + } + } + } + for (var col = 0; col < moduleCount; col++) { + for (var row = 0; row < moduleCount - 6; row++) { + if ( + qrCode.isDark(row, col) && + !qrCode.isDark(row + 1, col) && + qrCode.isDark(row + 2, col) && + qrCode.isDark(row + 3, col) && + qrCode.isDark(row + 4, col) && + !qrCode.isDark(row + 5, col) && + qrCode.isDark(row + 6, col) + ) { + lostPoint += 40 + } + } + } + var darkCount = 0 + for (var col = 0; col < moduleCount; col++) { + for (var row = 0; row < moduleCount; row++) { + if (qrCode.isDark(row, col)) { + darkCount++ + } + } + } + var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5 + lostPoint += ratio * 10 + return lostPoint + } + } + var QRMath = { + glog: function (n) { + if (n < 1) { + throw new Error('glog(' + n + ')') + } + return QRMath.LOG_TABLE[n] + }, + gexp: function (n) { + while (n < 0) { + n += 255 + } + while (n >= 256) { + n -= 255 + } + return QRMath.EXP_TABLE[n] + }, + EXP_TABLE: new Array(256), + LOG_TABLE: new Array(256) + } + for (var i = 0; i < 8; i++) { + QRMath.EXP_TABLE[i] = 1 << i + } + for (var i = 8; i < 256; i++) { + QRMath.EXP_TABLE[i] = + QRMath.EXP_TABLE[i - 4] ^ + QRMath.EXP_TABLE[i - 5] ^ + QRMath.EXP_TABLE[i - 6] ^ + QRMath.EXP_TABLE[i - 8] + } + for (var i = 0; i < 255; i++) { + QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]] = i + } + function QRPolynomial (num, shift) { + if (num.length == undefined) { + throw new Error(num.length + '/' + shift) + } + var offset = 0 + while (offset < num.length && num[offset] == 0) { + offset++ + } + this.num = new Array(num.length - offset + shift) + for (var i = 0; i < num.length - offset; i++) { + this.num[i] = num[i + offset] + } + } + QRPolynomial.prototype = { + get: function (index) { + return this.num[index] + }, + getLength: function () { + return this.num.length + }, + multiply: function (e) { + var num = new Array(this.getLength() + e.getLength() - 1) + for (var i = 0; i < this.getLength(); i++) { + for (var j = 0; j < e.getLength(); j++) { + num[i + j] ^= QRMath.gexp( + QRMath.glog(this.get(i)) + QRMath.glog(e.get(j)) + ) + } + } + return new QRPolynomial(num, 0) + }, + mod: function (e) { + if (this.getLength() - e.getLength() < 0) { + return this + } + var ratio = QRMath.glog(this.get(0)) - QRMath.glog(e.get(0)) + var num = new Array(this.getLength()) + for (var i = 0; i < this.getLength(); i++) { + num[i] = this.get(i) + } + for (var i = 0; i < e.getLength(); i++) { + num[i] ^= QRMath.gexp(QRMath.glog(e.get(i)) + ratio) + } + return new QRPolynomial(num, 0).mod(e) + } + } + function QRRSBlock (totalCount, dataCount) { + this.totalCount = totalCount + this.dataCount = dataCount + } + QRRSBlock.RS_BLOCK_TABLE = [ + [1, 26, 19], + [1, 26, 16], + [1, 26, 13], + [1, 26, 9], + [1, 44, 34], + [1, 44, 28], + [1, 44, 22], + [1, 44, 16], + [1, 70, 55], + [1, 70, 44], + [2, 35, 17], + [2, 35, 13], + [1, 100, 80], + [2, 50, 32], + [2, 50, 24], + [4, 25, 9], + [1, 134, 108], + [2, 67, 43], + [2, 33, 15, 2, 34, 16], + [2, 33, 11, 2, 34, 12], + [2, 86, 68], + [4, 43, 27], + [4, 43, 19], + [4, 43, 15], + [2, 98, 78], + [4, 49, 31], + [2, 32, 14, 4, 33, 15], + [4, 39, 13, 1, 40, 14], + [2, 121, 97], + [2, 60, 38, 2, 61, 39], + [4, 40, 18, 2, 41, 19], + [4, 40, 14, 2, 41, 15], + [2, 146, 116], + [3, 58, 36, 2, 59, 37], + [4, 36, 16, 4, 37, 17], + [4, 36, 12, 4, 37, 13], + [2, 86, 68, 2, 87, 69], + [4, 69, 43, 1, 70, 44], + [6, 43, 19, 2, 44, 20], + [6, 43, 15, 2, 44, 16], + [4, 101, 81], + [1, 80, 50, 4, 81, 51], + [4, 50, 22, 4, 51, 23], + [3, 36, 12, 8, 37, 13], + [2, 116, 92, 2, 117, 93], + [6, 58, 36, 2, 59, 37], + [4, 46, 20, 6, 47, 21], + [7, 42, 14, 4, 43, 15], + [4, 133, 107], + [8, 59, 37, 1, 60, 38], + [8, 44, 20, 4, 45, 21], + [12, 33, 11, 4, 34, 12], + [3, 145, 115, 1, 146, 116], + [4, 64, 40, 5, 65, 41], + [11, 36, 16, 5, 37, 17], + [11, 36, 12, 5, 37, 13], + [5, 109, 87, 1, 110, 88], + [5, 65, 41, 5, 66, 42], + [5, 54, 24, 7, 55, 25], + [11, 36, 12], + [5, 122, 98, 1, 123, 99], + [7, 73, 45, 3, 74, 46], + [15, 43, 19, 2, 44, 20], + [3, 45, 15, 13, 46, 16], + [1, 135, 107, 5, 136, 108], + [10, 74, 46, 1, 75, 47], + [1, 50, 22, 15, 51, 23], + [2, 42, 14, 17, 43, 15], + [5, 150, 120, 1, 151, 121], + [9, 69, 43, 4, 70, 44], + [17, 50, 22, 1, 51, 23], + [2, 42, 14, 19, 43, 15], + [3, 141, 113, 4, 142, 114], + [3, 70, 44, 11, 71, 45], + [17, 47, 21, 4, 48, 22], + [9, 39, 13, 16, 40, 14], + [3, 135, 107, 5, 136, 108], + [3, 67, 41, 13, 68, 42], + [15, 54, 24, 5, 55, 25], + [15, 43, 15, 10, 44, 16], + [4, 144, 116, 4, 145, 117], + [17, 68, 42], + [17, 50, 22, 6, 51, 23], + [19, 46, 16, 6, 47, 17], + [2, 139, 111, 7, 140, 112], + [17, 74, 46], + [7, 54, 24, 16, 55, 25], + [34, 37, 13], + [4, 151, 121, 5, 152, 122], + [4, 75, 47, 14, 76, 48], + [11, 54, 24, 14, 55, 25], + [16, 45, 15, 14, 46, 16], + [6, 147, 117, 4, 148, 118], + [6, 73, 45, 14, 74, 46], + [11, 54, 24, 16, 55, 25], + [30, 46, 16, 2, 47, 17], + [8, 132, 106, 4, 133, 107], + [8, 75, 47, 13, 76, 48], + [7, 54, 24, 22, 55, 25], + [22, 45, 15, 13, 46, 16], + [10, 142, 114, 2, 143, 115], + [19, 74, 46, 4, 75, 47], + [28, 50, 22, 6, 51, 23], + [33, 46, 16, 4, 47, 17], + [8, 152, 122, 4, 153, 123], + [22, 73, 45, 3, 74, 46], + [8, 53, 23, 26, 54, 24], + [12, 45, 15, 28, 46, 16], + [3, 147, 117, 10, 148, 118], + [3, 73, 45, 23, 74, 46], + [4, 54, 24, 31, 55, 25], + [11, 45, 15, 31, 46, 16], + [7, 146, 116, 7, 147, 117], + [21, 73, 45, 7, 74, 46], + [1, 53, 23, 37, 54, 24], + [19, 45, 15, 26, 46, 16], + [5, 145, 115, 10, 146, 116], + [19, 75, 47, 10, 76, 48], + [15, 54, 24, 25, 55, 25], + [23, 45, 15, 25, 46, 16], + [13, 145, 115, 3, 146, 116], + [2, 74, 46, 29, 75, 47], + [42, 54, 24, 1, 55, 25], + [23, 45, 15, 28, 46, 16], + [17, 145, 115], + [10, 74, 46, 23, 75, 47], + [10, 54, 24, 35, 55, 25], + [19, 45, 15, 35, 46, 16], + [17, 145, 115, 1, 146, 116], + [14, 74, 46, 21, 75, 47], + [29, 54, 24, 19, 55, 25], + [11, 45, 15, 46, 46, 16], + [13, 145, 115, 6, 146, 116], + [14, 74, 46, 23, 75, 47], + [44, 54, 24, 7, 55, 25], + [59, 46, 16, 1, 47, 17], + [12, 151, 121, 7, 152, 122], + [12, 75, 47, 26, 76, 48], + [39, 54, 24, 14, 55, 25], + [22, 45, 15, 41, 46, 16], + [6, 151, 121, 14, 152, 122], + [6, 75, 47, 34, 76, 48], + [46, 54, 24, 10, 55, 25], + [2, 45, 15, 64, 46, 16], + [17, 152, 122, 4, 153, 123], + [29, 74, 46, 14, 75, 47], + [49, 54, 24, 10, 55, 25], + [24, 45, 15, 46, 46, 16], + [4, 152, 122, 18, 153, 123], + [13, 74, 46, 32, 75, 47], + [48, 54, 24, 14, 55, 25], + [42, 45, 15, 32, 46, 16], + [20, 147, 117, 4, 148, 118], + [40, 75, 47, 7, 76, 48], + [43, 54, 24, 22, 55, 25], + [10, 45, 15, 67, 46, 16], + [19, 148, 118, 6, 149, 119], + [18, 75, 47, 31, 76, 48], + [34, 54, 24, 34, 55, 25], + [20, 45, 15, 61, 46, 16] + ] + QRRSBlock.getRSBlocks = function (typeNumber, errorCorrectLevel) { + var rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel) + if (rsBlock == undefined) { + throw new Error( + 'bad rs block @ typeNumber:' + + typeNumber + + '/errorCorrectLevel:' + + errorCorrectLevel + ) + } + var length = rsBlock.length / 3 + var list = [] + for (var i = 0; i < length; i++) { + var count = rsBlock[i * 3 + 0] + var totalCount = rsBlock[i * 3 + 1] + var dataCount = rsBlock[i * 3 + 2] + for (var j = 0; j < count; j++) { + list.push(new QRRSBlock(totalCount, dataCount)) + } + } + return list + } + QRRSBlock.getRsBlockTable = function (typeNumber, errorCorrectLevel) { + switch (errorCorrectLevel) { + case QRErrorCorrectLevel.L: + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0] + case QRErrorCorrectLevel.M: + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1] + case QRErrorCorrectLevel.Q: + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2] + case QRErrorCorrectLevel.H: + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3] + default: + return undefined + } + } + function QRBitBuffer () { + this.buffer = [] + this.length = 0 + } + QRBitBuffer.prototype = { + get: function (index) { + var bufIndex = Math.floor(index / 8) + return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) == 1 + }, + put: function (num, length) { + for (var i = 0; i < length; i++) { + this.putBit(((num >>> (length - i - 1)) & 1) == 1) + } + }, + getLengthInBits: function () { + return this.length + }, + putBit: function (bit) { + var bufIndex = Math.floor(this.length / 8) + if (this.buffer.length <= bufIndex) { + this.buffer.push(0) + } + if (bit) { + this.buffer[bufIndex] |= 0x80 >>> (this.length % 8) + } + this.length++ + } + } + var QRCodeLimitLength = [ + [17, 14, 11, 7], + [32, 26, 20, 14], + [53, 42, 32, 24], + [78, 62, 46, 34], + [106, 84, 60, 44], + [134, 106, 74, 58], + [154, 122, 86, 64], + [192, 152, 108, 84], + [230, 180, 130, 98], + [271, 213, 151, 119], + [321, 251, 177, 137], + [367, 287, 203, 155], + [425, 331, 241, 177], + [458, 362, 258, 194], + [520, 412, 292, 220], + [586, 450, 322, 250], + [644, 504, 364, 280], + [718, 560, 394, 310], + [792, 624, 442, 338], + [858, 666, 482, 382], + [929, 711, 509, 403], + [1003, 779, 565, 439], + [1091, 857, 611, 461], + [1171, 911, 661, 511], + [1273, 997, 715, 535], + [1367, 1059, 751, 593], + [1465, 1125, 805, 625], + [1528, 1190, 868, 658], + [1628, 1264, 908, 698], + [1732, 1370, 982, 742], + [1840, 1452, 1030, 790], + [1952, 1538, 1112, 842], + [2068, 1628, 1168, 898], + [2188, 1722, 1228, 958], + [2303, 1809, 1283, 983], + [2431, 1911, 1351, 1051], + [2563, 1989, 1423, 1093], + [2699, 2099, 1499, 1139], + [2809, 2213, 1579, 1219], + [2953, 2331, 1663, 1273] + ] + + function _isSupportCanvas () { + return typeof CanvasRenderingContext2D !== 'undefined' + } + + // android 2.x doesn't support Data-URI spec + function _getAndroid () { + var android = false + var sAgent = navigator.userAgent + + if (/android/i.test(sAgent)) { + // android + android = true + var aMat = sAgent.toString().match(/android ([0-9]\.[0-9])/i) + + if (aMat && aMat[1]) { + android = parseFloat(aMat[1]) + } + } + + return android + } + + var svgDrawer = (function () { + var Drawing = function (el, htOption) { + this._el = el + this._htOption = htOption + } + + Drawing.prototype.draw = function (oQRCode) { + var _htOption = this._htOption + var _el = this._el + var nCount = oQRCode.getModuleCount() + var nWidth = Math.floor(_htOption.width / nCount) + var nHeight = Math.floor(_htOption.height / nCount) + + this.clear() + + function makeSVG (tag, attrs) { + var el = document.createElementNS('http://www.w3.org/2000/svg', tag) + for (var k in attrs) { + if (attrs.hasOwnProperty(k)) el.setAttribute(k, attrs[k]) + } + return el + } + + var svg = makeSVG('svg', { + viewBox: '0 0 ' + String(nCount) + ' ' + String(nCount), + width: '100%', + height: '100%', + fill: _htOption.colorLight + }) + svg.setAttributeNS( + 'http://www.w3.org/2000/xmlns/', + 'xmlns:xlink', + 'http://www.w3.org/1999/xlink' + ) + _el.appendChild(svg) + + svg.appendChild( + makeSVG('rect', { + fill: _htOption.colorLight, + width: '100%', + height: '100%' + }) + ) + svg.appendChild( + makeSVG('rect', { + fill: _htOption.colorDark, + width: '1', + height: '1', + id: 'template' + }) + ) + + for (var row = 0; row < nCount; row++) { + for (var col = 0; col < nCount; col++) { + if (oQRCode.isDark(row, col)) { + var child = makeSVG('use', { x: String(col), y: String(row) }) + child.setAttributeNS( + 'http://www.w3.org/1999/xlink', + 'href', + '#template' + ) + svg.appendChild(child) + } + } + } + } + Drawing.prototype.clear = function () { + while (this._el.hasChildNodes()) this._el.removeChild(this._el.lastChild) + } + return Drawing + })() + + var useSVG = document.documentElement.tagName.toLowerCase() === 'svg' + + // Drawing in DOM by using Table tag + var Drawing = useSVG + ? svgDrawer + : !_isSupportCanvas() + ? (function () { + var Drawing = function (el, htOption) { + this._el = el + this._htOption = htOption + } + + /** + * Draw the QRCode + * + * @param {QRCode} oQRCode + */ + Drawing.prototype.draw = function (oQRCode) { + var _htOption = this._htOption + var _el = this._el + var nCount = oQRCode.getModuleCount() + var nWidth = Math.floor(_htOption.width / nCount) + var nHeight = Math.floor(_htOption.height / nCount) + var aHTML = [''] + + for (var row = 0; row < nCount; row++) { + aHTML.push('') + + for (var col = 0; col < nCount; col++) { + aHTML.push( + '' + ) + } + + aHTML.push('') + } + + aHTML.push('
') + _el.innerHTML = aHTML.join('') + + // Fix the margin values as real size. + var elTable = _el.childNodes[0] + var nLeftMarginTable = (_htOption.width - elTable.offsetWidth) / 2 + var nTopMarginTable = (_htOption.height - elTable.offsetHeight) / 2 + + if (nLeftMarginTable > 0 && nTopMarginTable > 0) { + elTable.style.margin = + nTopMarginTable + 'px ' + nLeftMarginTable + 'px' + } + } + + /** + * Clear the QRCode + */ + Drawing.prototype.clear = function () { + this._el.innerHTML = '' + } + + return Drawing + })() + : (function () { + // Drawing in Canvas + function _onMakeImage () { + this._elImage.src = this._elCanvas.toDataURL('image/png') + this._elImage.style.display = 'block' + this._elCanvas.style.display = 'none' + } + + // Android 2.1 bug workaround + // http://code.google.com/p/android/issues/detail?id=5141 + if (this._android && this._android <= 2.1) { + var factor = 1 / window.devicePixelRatio + var drawImage = CanvasRenderingContext2D.prototype.drawImage + CanvasRenderingContext2D.prototype.drawImage = function ( + image, + sx, + sy, + sw, + sh, + dx, + dy, + dw, + dh + ) { + if ('nodeName' in image && /img/i.test(image.nodeName)) { + for (var i = arguments.length - 1; i >= 1; i--) { + arguments[i] = arguments[i] * factor + } + } else if (typeof dw === 'undefined') { + arguments[1] *= factor + arguments[2] *= factor + arguments[3] *= factor + arguments[4] *= factor + } + + drawImage.apply(this, arguments) + } + } + + /** + * Check whether the user's browser supports Data URI or not + * + * @private + * @param {Function} fSuccess Occurs if it supports Data URI + * @param {Function} fFail Occurs if it doesn't support Data URI + */ + function _safeSetDataURI (fSuccess, fFail) { + var self = this + self._fFail = fFail + self._fSuccess = fSuccess + + // Check it just once + if (self._bSupportDataURI === null) { + var el = document.createElement('img') + var fOnError = function () { + self._bSupportDataURI = false + + if (self._fFail) { + self._fFail.call(self) + } + } + var fOnSuccess = function () { + self._bSupportDataURI = true + + if (self._fSuccess) { + self._fSuccess.call(self) + } + } + + el.onabort = fOnError + el.onerror = fOnError + el.onload = fOnSuccess + el.src = + 'data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==' // the Image contains 1px data. + } else if (self._bSupportDataURI === true && self._fSuccess) { + self._fSuccess.call(self) + } else if (self._bSupportDataURI === false && self._fFail) { + self._fFail.call(self) + } + } + + /** + * Drawing QRCode by using canvas + * + * @constructor + * @param {HTMLElement} el + * @param {Object} htOption QRCode Options + */ + var Drawing = function (el, htOption) { + this._bIsPainted = false + this._android = _getAndroid() + + this._htOption = htOption + this._elCanvas = document.createElement('canvas') + this._elCanvas.width = htOption.width + this._elCanvas.height = htOption.height + el.appendChild(this._elCanvas) + this._el = el + this._oContext = this._elCanvas.getContext('2d') + this._bIsPainted = false + this._elImage = document.createElement('img') + this._elImage.alt = 'Scan me!' + this._elImage.style.display = 'none' + this._el.appendChild(this._elImage) + this._bSupportDataURI = null + } + + /** + * Draw the QRCode + * + * @param {QRCode} oQRCode + */ + Drawing.prototype.draw = function (oQRCode) { + var _elImage = this._elImage + var _oContext = this._oContext + var _htOption = this._htOption + + var nCount = oQRCode.getModuleCount() + var nWidth = _htOption.width / nCount + var nHeight = _htOption.height / nCount + var nRoundedWidth = Math.round(nWidth) + var nRoundedHeight = Math.round(nHeight) + + _elImage.style.display = 'none' + this.clear() + + for (var row = 0; row < nCount; row++) { + for (var col = 0; col < nCount; col++) { + var bIsDark = oQRCode.isDark(row, col) + var nLeft = col * nWidth + var nTop = row * nHeight + _oContext.strokeStyle = bIsDark + ? _htOption.colorDark + : _htOption.colorLight + _oContext.lineWidth = 1 + _oContext.fillStyle = bIsDark + ? _htOption.colorDark + : _htOption.colorLight + _oContext.fillRect(nLeft, nTop, nWidth, nHeight) + + // 안티 앨리어싱 방지 처리 + _oContext.strokeRect( + Math.floor(nLeft) + 0.5, + Math.floor(nTop) + 0.5, + nRoundedWidth, + nRoundedHeight + ) + + _oContext.strokeRect( + Math.ceil(nLeft) - 0.5, + Math.ceil(nTop) - 0.5, + nRoundedWidth, + nRoundedHeight + ) + } + } + + this._bIsPainted = true + } + + /** + * Make the image from Canvas if the browser supports Data URI. + */ + Drawing.prototype.makeImage = function () { + if (this._bIsPainted) { + _safeSetDataURI.call(this, _onMakeImage) + } + } + + /** + * Return whether the QRCode is painted or not + * + * @return {Boolean} + */ + Drawing.prototype.isPainted = function () { + return this._bIsPainted + } + + /** + * Clear the QRCode + */ + Drawing.prototype.clear = function () { + this._oContext.clearRect( + 0, + 0, + this._elCanvas.width, + this._elCanvas.height + ) + this._bIsPainted = false + } + + /** + * @private + * @param {Number} nNumber + */ + Drawing.prototype.round = function (nNumber) { + if (!nNumber) { + return nNumber + } + + return Math.floor(nNumber * 1000) / 1000 + } + + return Drawing + })() + + /** + * Get the type by string length + * + * @private + * @param {String} sText + * @param {Number} nCorrectLevel + * @return {Number} type + */ + function _getTypeNumber (sText, nCorrectLevel) { + var nType = 1 + var length = _getUTF8Length(sText) + + for (var i = 0, len = QRCodeLimitLength.length; i <= len; i++) { + var nLimit = 0 + + switch (nCorrectLevel) { + case QRErrorCorrectLevel.L: + nLimit = QRCodeLimitLength[i][0] + break + case QRErrorCorrectLevel.M: + nLimit = QRCodeLimitLength[i][1] + break + case QRErrorCorrectLevel.Q: + nLimit = QRCodeLimitLength[i][2] + break + case QRErrorCorrectLevel.H: + nLimit = QRCodeLimitLength[i][3] + break + } + + if (length <= nLimit) { + break + } else { + nType++ + } + } + + if (nType > QRCodeLimitLength.length) { + throw new Error('Too long data') + } + + return nType + } + + function _getUTF8Length (sText) { + var replacedText = encodeURI(sText) + .toString() + .replace(/\%[0-9a-fA-F]{2}/g, 'a') + return replacedText.length + (replacedText.length != sText ? 3 : 0) + } + + /** + * @class QRCode + * @constructor + * @example + * new QRCode(document.getElementById("test"), "http://jindo.dev.naver.com/collie"); + * + * @example + * var oQRCode = new QRCode("test", { + * text : "http://naver.com", + * width : 128, + * height : 128 + * }); + * + * oQRCode.clear(); // Clear the QRCode. + * oQRCode.makeCode("http://map.naver.com"); // Re-create the QRCode. + * + * @param {HTMLElement|String} el target element or 'id' attribute of element. + * @param {Object|String} vOption + * @param {String} vOption.text QRCode link data + * @param {Number} [vOption.width=256] + * @param {Number} [vOption.height=256] + * @param {String} [vOption.colorDark="#000000"] + * @param {String} [vOption.colorLight="#ffffff"] + * @param {QRCode.CorrectLevel} [vOption.correctLevel=QRCode.CorrectLevel.H] [L|M|Q|H] + */ + QRCode = function (el, vOption) { + this._htOption = { + width: 256, + height: 256, + typeNumber: 4, + colorDark: '#000000', + colorLight: '#ffffff', + correctLevel: QRErrorCorrectLevel.H + } + + if (typeof vOption === 'string') { + vOption = { + text: vOption + } + } + + // Overwrites options + if (vOption) { + for (var i in vOption) { + this._htOption[i] = vOption[i] + } + } + + if (typeof el === 'string') { + el = document.getElementById(el) + } + + if (this._htOption.useSVG) { + Drawing = svgDrawer + } + + this._android = _getAndroid() + this._el = el + this._oQRCode = null + this._oDrawing = new Drawing(this._el, this._htOption) + + if (this._htOption.text) { + this.makeCode(this._htOption.text) + } + } + + /** + * Make the QRCode + * + * @param {String} sText link data + */ + QRCode.prototype.makeCode = function (sText) { + this._oQRCode = new QRCodeModel( + _getTypeNumber(sText, this._htOption.correctLevel), + this._htOption.correctLevel + ) + this._oQRCode.addData(sText) + this._oQRCode.make() + this._el.title = sText + this._oDrawing.draw(this._oQRCode) + this.makeImage() + } + + /** + * Make the Image from Canvas element + * - It occurs automatically + * - Android below 3 doesn't support Data-URI spec. + * + * @private + */ + QRCode.prototype.makeImage = function () { + if ( + typeof this._oDrawing.makeImage === 'function' && + (!this._android || this._android >= 3) + ) { + this._oDrawing.makeImage() + } + } + + /** + * Clear the QRCode + */ + QRCode.prototype.clear = function () { + this._oDrawing.clear() + } + + /** + * @name QRCode.CorrectLevel + */ + QRCode.CorrectLevel = QRErrorCorrectLevel +})() diff --git a/testing/web-platform/tests/tools/wave/www/lib/jszip.min.js b/testing/web-platform/tests/tools/wave/www/lib/jszip.min.js new file mode 100644 index 0000000000..b9188736b7 --- /dev/null +++ b/testing/web-platform/tests/tools/wave/www/lib/jszip.min.js @@ -0,0 +1,15 @@ +/*! + +JSZip v3.1.5 - A JavaScript class for generating and reading zip files + + +(c) 2009-2016 Stuart Knightley +Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/jszip/master/LICENSE.markdown. + +JSZip uses the library pako released under the MIT license : +https://github.com/nodeca/pako/blob/master/LICENSE +*/ +!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.JSZip=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g>2,h=(3&b)<<4|c>>4,i=n>1?(15&c)<<2|e>>6:64,j=n>2?63&e:64,k.push(f.charAt(g)+f.charAt(h)+f.charAt(i)+f.charAt(j));return k.join("")},c.decode=function(a){var b,c,d,g,h,i,j,k=0,l=0,m="data:";if(a.substr(0,m.length)===m)throw new Error("Invalid base64 input, it looks like a data url.");a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");var n=3*a.length/4;if(a.charAt(a.length-1)===f.charAt(64)&&n--,a.charAt(a.length-2)===f.charAt(64)&&n--,n%1!==0)throw new Error("Invalid base64 input, bad content length.");var o;for(o=e.uint8array?new Uint8Array(0|n):new Array(0|n);k>4,c=(15&h)<<4|i>>2,d=(3&i)<<6|j,o[l++]=b,64!==i&&(o[l++]=c),64!==j&&(o[l++]=d);return o}},{"./support":30,"./utils":32}],2:[function(a,b,c){"use strict";function d(a,b,c,d,e){this.compressedSize=a,this.uncompressedSize=b,this.crc32=c,this.compression=d,this.compressedContent=e}var e=a("./external"),f=a("./stream/DataWorker"),g=a("./stream/DataLengthProbe"),h=a("./stream/Crc32Probe"),g=a("./stream/DataLengthProbe");d.prototype={getContentWorker:function(){var a=new f(e.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new g("data_length")),b=this;return a.on("end",function(){if(this.streamInfo.data_length!==b.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),a},getCompressedWorker:function(){return new f(e.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},d.createWorkerFrom=function(a,b,c){return a.pipe(new h).pipe(new g("uncompressedSize")).pipe(b.compressWorker(c)).pipe(new g("compressedSize")).withStreamInfo("compression",b)},b.exports=d},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(a,b,c){"use strict";var d=a("./stream/GenericWorker");c.STORE={magic:"\0\0",compressWorker:function(a){return new d("STORE compression")},uncompressWorker:function(){return new d("STORE decompression")}},c.DEFLATE=a("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(a,b,c){"use strict";function d(){for(var a,b=[],c=0;c<256;c++){a=c;for(var d=0;d<8;d++)a=1&a?3988292384^a>>>1:a>>>1;b[c]=a}return b}function e(a,b,c,d){var e=h,f=d+c;a^=-1;for(var g=d;g>>8^e[255&(a^b[g])];return a^-1}function f(a,b,c,d){var e=h,f=d+c;a^=-1;for(var g=d;g>>8^e[255&(a^b.charCodeAt(g))];return a^-1}var g=a("./utils"),h=d();b.exports=function(a,b){if("undefined"==typeof a||!a.length)return 0;var c="string"!==g.getTypeOf(a);return c?e(0|b,a,a.length,0):f(0|b,a,a.length,0)}},{"./utils":32}],5:[function(a,b,c){"use strict";c.base64=!1,c.binary=!1,c.dir=!1,c.createFolders=!0,c.date=null,c.compression=null,c.compressionOptions=null,c.comment=null,c.unixPermissions=null,c.dosPermissions=null},{}],6:[function(a,b,c){"use strict";var d=null;d="undefined"!=typeof Promise?Promise:a("lie"),b.exports={Promise:d}},{lie:58}],7:[function(a,b,c){"use strict";function d(a,b){h.call(this,"FlateWorker/"+a),this._pako=null,this._pakoAction=a,this._pakoOptions=b,this.meta={}}var e="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,f=a("pako"),g=a("./utils"),h=a("./stream/GenericWorker"),i=e?"uint8array":"array";c.magic="\b\0",g.inherits(d,h),d.prototype.processChunk=function(a){this.meta=a.meta,null===this._pako&&this._createPako(),this._pako.push(g.transformTo(i,a.data),!1)},d.prototype.flush=function(){h.prototype.flush.call(this),null===this._pako&&this._createPako(),this._pako.push([],!0)},d.prototype.cleanUp=function(){h.prototype.cleanUp.call(this),this._pako=null},d.prototype._createPako=function(){this._pako=new f[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var a=this;this._pako.onData=function(b){a.push({data:b,meta:a.meta})}},c.compressWorker=function(a){return new d("Deflate",a)},c.uncompressWorker=function(){return new d("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:59}],8:[function(a,b,c){"use strict";function d(a,b,c,d){f.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=b,this.zipPlatform=c,this.encodeFileName=d,this.streamFiles=a,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}var e=a("../utils"),f=a("../stream/GenericWorker"),g=a("../utf8"),h=a("../crc32"),i=a("../signature"),j=function(a,b){var c,d="";for(c=0;c>>=8;return d},k=function(a,b){var c=a;return a||(c=b?16893:33204),(65535&c)<<16},l=function(a,b){return 63&(a||0)},m=function(a,b,c,d,f,m){var n,o,p=a.file,q=a.compression,r=m!==g.utf8encode,s=e.transformTo("string",m(p.name)),t=e.transformTo("string",g.utf8encode(p.name)),u=p.comment,v=e.transformTo("string",m(u)),w=e.transformTo("string",g.utf8encode(u)),x=t.length!==p.name.length,y=w.length!==u.length,z="",A="",B="",C=p.dir,D=p.date,E={crc32:0,compressedSize:0,uncompressedSize:0};b&&!c||(E.crc32=a.crc32,E.compressedSize=a.compressedSize,E.uncompressedSize=a.uncompressedSize);var F=0;b&&(F|=8),r||!x&&!y||(F|=2048);var G=0,H=0;C&&(G|=16),"UNIX"===f?(H=798,G|=k(p.unixPermissions,C)):(H=20,G|=l(p.dosPermissions,C)),n=D.getUTCHours(),n<<=6,n|=D.getUTCMinutes(),n<<=5,n|=D.getUTCSeconds()/2,o=D.getUTCFullYear()-1980,o<<=4,o|=D.getUTCMonth()+1,o<<=5,o|=D.getUTCDate(),x&&(A=j(1,1)+j(h(s),4)+t,z+="up"+j(A.length,2)+A),y&&(B=j(1,1)+j(h(v),4)+w,z+="uc"+j(B.length,2)+B);var I="";I+="\n\0",I+=j(F,2),I+=q.magic,I+=j(n,2),I+=j(o,2),I+=j(E.crc32,4),I+=j(E.compressedSize,4),I+=j(E.uncompressedSize,4),I+=j(s.length,2),I+=j(z.length,2);var J=i.LOCAL_FILE_HEADER+I+s+z,K=i.CENTRAL_FILE_HEADER+j(H,2)+I+j(v.length,2)+"\0\0\0\0"+j(G,4)+j(d,4)+s+z+v;return{fileRecord:J,dirRecord:K}},n=function(a,b,c,d,f){var g="",h=e.transformTo("string",f(d));return g=i.CENTRAL_DIRECTORY_END+"\0\0\0\0"+j(a,2)+j(a,2)+j(b,4)+j(c,4)+j(h.length,2)+h},o=function(a){var b="";return b=i.DATA_DESCRIPTOR+j(a.crc32,4)+j(a.compressedSize,4)+j(a.uncompressedSize,4)};e.inherits(d,f),d.prototype.push=function(a){var b=a.meta.percent||0,c=this.entriesCount,d=this._sources.length;this.accumulate?this.contentBuffer.push(a):(this.bytesWritten+=a.data.length,f.prototype.push.call(this,{data:a.data,meta:{currentFile:this.currentFile,percent:c?(b+100*(c-d-1))/c:100}}))},d.prototype.openedSource=function(a){this.currentSourceOffset=this.bytesWritten,this.currentFile=a.file.name;var b=this.streamFiles&&!a.file.dir;if(b){var c=m(a,b,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:c.fileRecord,meta:{percent:0}})}else this.accumulate=!0},d.prototype.closedSource=function(a){this.accumulate=!1;var b=this.streamFiles&&!a.file.dir,c=m(a,b,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(c.dirRecord),b)this.push({data:o(a),meta:{percent:100}});else for(this.push({data:c.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},d.prototype.flush=function(){for(var a=this.bytesWritten,b=0;b0?a.substring(0,b):""},q=function(a){return"/"!==a.slice(-1)&&(a+="/"),a},r=function(a,b){return b="undefined"!=typeof b?b:i.createFolders,a=q(a),this.files[a]||o.call(this,a,null,{dir:!0,createFolders:b}),this.files[a]},s={load:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},forEach:function(a){var b,c,d;for(b in this.files)this.files.hasOwnProperty(b)&&(d=this.files[b],c=b.slice(this.root.length,b.length),c&&b.slice(0,this.root.length)===this.root&&a(c,d))},filter:function(a){var b=[];return this.forEach(function(c,d){a(c,d)&&b.push(d)}),b},file:function(a,b,c){if(1===arguments.length){if(d(a)){var e=a;return this.filter(function(a,b){return!b.dir&&e.test(a)})}var f=this.files[this.root+a];return f&&!f.dir?f:null}return a=this.root+a,o.call(this,a,b,c),this},folder:function(a){if(!a)return this;if(d(a))return this.filter(function(b,c){return c.dir&&a.test(b)});var b=this.root+a,c=r.call(this,b),e=this.clone();return e.root=c.name,e},remove:function(a){a=this.root+a;var b=this.files[a];if(b||("/"!==a.slice(-1)&&(a+="/"),b=this.files[a]),b&&!b.dir)delete this.files[a];else for(var c=this.filter(function(b,c){return c.name.slice(0,a.length)===a}),d=0;d=0;--f)if(this.data[f]===b&&this.data[f+1]===c&&this.data[f+2]===d&&this.data[f+3]===e)return f-this.zero;return-1},d.prototype.readAndCheckSignature=function(a){var b=a.charCodeAt(0),c=a.charCodeAt(1),d=a.charCodeAt(2),e=a.charCodeAt(3),f=this.readData(4);return b===f[0]&&c===f[1]&&d===f[2]&&e===f[3]},d.prototype.readData=function(a){if(this.checkOffset(a),0===a)return[];var b=this.data.slice(this.zero+this.index,this.zero+this.index+a);return this.index+=a,b},b.exports=d},{"../utils":32,"./DataReader":18}],18:[function(a,b,c){"use strict";function d(a){this.data=a,this.length=a.length,this.index=0,this.zero=0}var e=a("../utils");d.prototype={checkOffset:function(a){this.checkIndex(this.index+a)},checkIndex:function(a){if(this.length=this.index;b--)c=(c<<8)+this.byteAt(b);return this.index+=a,c},readString:function(a){return e.transformTo("string",this.readData(a))},readData:function(a){},lastIndexOfSignature:function(a){},readAndCheckSignature:function(a){},readDate:function(){var a=this.readInt(4);return new Date(Date.UTC((a>>25&127)+1980,(a>>21&15)-1,a>>16&31,a>>11&31,a>>5&63,(31&a)<<1))}},b.exports=d},{"../utils":32}],19:[function(a,b,c){"use strict";function d(a){e.call(this,a)}var e=a("./Uint8ArrayReader"),f=a("../utils");f.inherits(d,e),d.prototype.readData=function(a){this.checkOffset(a);var b=this.data.slice(this.zero+this.index,this.zero+this.index+a);return this.index+=a,b},b.exports=d},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(a,b,c){"use strict";function d(a){e.call(this,a)}var e=a("./DataReader"),f=a("../utils");f.inherits(d,e),d.prototype.byteAt=function(a){return this.data.charCodeAt(this.zero+a)},d.prototype.lastIndexOfSignature=function(a){return this.data.lastIndexOf(a)-this.zero},d.prototype.readAndCheckSignature=function(a){var b=this.readData(4);return a===b},d.prototype.readData=function(a){this.checkOffset(a);var b=this.data.slice(this.zero+this.index,this.zero+this.index+a);return this.index+=a,b},b.exports=d},{"../utils":32,"./DataReader":18}],21:[function(a,b,c){"use strict";function d(a){e.call(this,a)}var e=a("./ArrayReader"),f=a("../utils");f.inherits(d,e),d.prototype.readData=function(a){if(this.checkOffset(a),0===a)return new Uint8Array(0);var b=this.data.subarray(this.zero+this.index,this.zero+this.index+a);return this.index+=a,b},b.exports=d},{"../utils":32,"./ArrayReader":17}],22:[function(a,b,c){"use strict";var d=a("../utils"),e=a("../support"),f=a("./ArrayReader"),g=a("./StringReader"),h=a("./NodeBufferReader"),i=a("./Uint8ArrayReader");b.exports=function(a){var b=d.getTypeOf(a);return d.checkSupport(b),"string"!==b||e.uint8array?"nodebuffer"===b?new h(a):e.uint8array?new i(d.transformTo("uint8array",a)):new f(d.transformTo("array",a)):new g(a)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(a,b,c){"use strict";c.LOCAL_FILE_HEADER="PK",c.CENTRAL_FILE_HEADER="PK",c.CENTRAL_DIRECTORY_END="PK",c.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK",c.ZIP64_CENTRAL_DIRECTORY_END="PK",c.DATA_DESCRIPTOR="PK\b"},{}],24:[function(a,b,c){"use strict";function d(a){e.call(this,"ConvertWorker to "+a),this.destType=a}var e=a("./GenericWorker"),f=a("../utils");f.inherits(d,e),d.prototype.processChunk=function(a){this.push({data:f.transformTo(this.destType,a.data),meta:a.meta})},b.exports=d},{"../utils":32,"./GenericWorker":28}],25:[function(a,b,c){"use strict";function d(){e.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}var e=a("./GenericWorker"),f=a("../crc32"),g=a("../utils");g.inherits(d,e),d.prototype.processChunk=function(a){this.streamInfo.crc32=f(a.data,this.streamInfo.crc32||0),this.push(a)},b.exports=d},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(a,b,c){"use strict";function d(a){f.call(this,"DataLengthProbe for "+a),this.propName=a,this.withStreamInfo(a,0)}var e=a("../utils"),f=a("./GenericWorker");e.inherits(d,f),d.prototype.processChunk=function(a){if(a){var b=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=b+a.data.length}f.prototype.processChunk.call(this,a)},b.exports=d},{"../utils":32,"./GenericWorker":28}],27:[function(a,b,c){"use strict";function d(a){f.call(this,"DataWorker");var b=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,a.then(function(a){b.dataIsReady=!0,b.data=a,b.max=a&&a.length||0,b.type=e.getTypeOf(a),b.isPaused||b._tickAndRepeat()},function(a){b.error(a)})}var e=a("../utils"),f=a("./GenericWorker"),g=16384;e.inherits(d,f),d.prototype.cleanUp=function(){f.prototype.cleanUp.call(this),this.data=null},d.prototype.resume=function(){return!!f.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,e.delay(this._tickAndRepeat,[],this)),!0)},d.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(e.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},d.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var a=g,b=null,c=Math.min(this.max,this.index+a);if(this.index>=this.max)return this.end();switch(this.type){case"string":b=this.data.substring(this.index,c);break;case"uint8array":b=this.data.subarray(this.index,c);break;case"array":case"nodebuffer":b=this.data.slice(this.index,c)}return this.index=c,this.push({data:b,meta:{percent:this.max?this.index/this.max*100:0}})},b.exports=d},{"../utils":32,"./GenericWorker":28}],28:[function(a,b,c){"use strict";function d(a){this.name=a||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}d.prototype={push:function(a){this.emit("data",a)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(a){this.emit("error",a)}return!0},error:function(a){return!this.isFinished&&(this.isPaused?this.generatedError=a:(this.isFinished=!0,this.emit("error",a),this.previous&&this.previous.error(a),this.cleanUp()),!0)},on:function(a,b){return this._listeners[a].push(b),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(a,b){if(this._listeners[a])for(var c=0;c "+a:a}},b.exports=d},{}],29:[function(a,b,c){"use strict";function d(a,b,c){switch(a){case"blob":return h.newBlob(h.transformTo("arraybuffer",b),c);case"base64":return k.encode(b);default:return h.transformTo(a,b)}}function e(a,b){var c,d=0,e=null,f=0;for(c=0;c=252?6:k>=248?5:k>=240?4:k>=224?3:k>=192?2:1;j[254]=j[254]=1;var l=function(a){var b,c,d,e,f,h=a.length,i=0;for(e=0;e>>6,b[f++]=128|63&c):c<65536?(b[f++]=224|c>>>12,b[f++]=128|c>>>6&63,b[f++]=128|63&c):(b[f++]=240|c>>>18,b[f++]=128|c>>>12&63,b[f++]=128|c>>>6&63,b[f++]=128|63&c);return b},m=function(a,b){var c;for(b=b||a.length,b>a.length&&(b=a.length),c=b-1;c>=0&&128===(192&a[c]);)c--;return c<0?b:0===c?b:c+j[a[c]]>b?c:b},n=function(a){var b,c,d,e,g=a.length,h=new Array(2*g);for(c=0,b=0;b4)h[c++]=65533,b+=e-1;else{for(d&=2===e?31:3===e?15:7;e>1&&b1?h[c++]=65533:d<65536?h[c++]=d:(d-=65536,h[c++]=55296|d>>10&1023,h[c++]=56320|1023&d)}return h.length!==c&&(h.subarray?h=h.subarray(0,c):h.length=c),f.applyFromCharCode(h)};c.utf8encode=function(a){return g.nodebuffer?h.newBufferFrom(a,"utf-8"):l(a)},c.utf8decode=function(a){return g.nodebuffer?f.transformTo("nodebuffer",a).toString("utf-8"):(a=f.transformTo(g.uint8array?"uint8array":"array",a),n(a))},f.inherits(d,i),d.prototype.processChunk=function(a){var b=f.transformTo(g.uint8array?"uint8array":"array",a.data);if(this.leftOver&&this.leftOver.length){if(g.uint8array){var d=b;b=new Uint8Array(d.length+this.leftOver.length),b.set(this.leftOver,0),b.set(d,this.leftOver.length)}else b=this.leftOver.concat(b);this.leftOver=null}var e=m(b),h=b;e!==b.length&&(g.uint8array?(h=b.subarray(0,e),this.leftOver=b.subarray(e,b.length)):(h=b.slice(0,e),this.leftOver=b.slice(e,b.length))),this.push({data:c.utf8decode(h),meta:a.meta})},d.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:c.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},c.Utf8DecodeWorker=d,f.inherits(e,i),e.prototype.processChunk=function(a){this.push({data:c.utf8encode(a.data),meta:a.meta})},c.Utf8EncodeWorker=e},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(a,b,c){"use strict";function d(a){var b=null;return b=i.uint8array?new Uint8Array(a.length):new Array(a.length),f(a,b)}function e(a){return a}function f(a,b){for(var c=0;c1;)try{return n.stringifyByChunk(a,d,b)}catch(f){b=Math.floor(b/2)}return n.stringifyByChar(a)}function h(a,b){for(var c=0;c1)throw new Error("Multi-volumes zip are not supported")},readLocalFiles:function(){var a,b;for(a=0;a0)this.isSignature(c,g.CENTRAL_FILE_HEADER)||(this.reader.zero=e);else if(e<0)throw new Error("Corrupted zip: missing "+Math.abs(e)+" bytes.")},prepareReader:function(a){this.reader=e(a)},load:function(a){this.prepareReader(a),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},b.exports=d},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utf8":31,"./utils":32,"./zipEntry":34}],34:[function(a,b,c){"use strict";function d(a,b){this.options=a,this.loadOptions=b}var e=a("./reader/readerFor"),f=a("./utils"),g=a("./compressedObject"),h=a("./crc32"),i=a("./utf8"),j=a("./compressions"),k=a("./support"),l=0,m=3,n=function(a){for(var b in j)if(j.hasOwnProperty(b)&&j[b].magic===a)return j[b];return null};d.prototype={isEncrypted:function(){return 1===(1&this.bitFlag)},useUTF8:function(){return 2048===(2048&this.bitFlag)},readLocalPart:function(a){var b,c;if(a.skip(22),this.fileNameLength=a.readInt(2),c=a.readInt(2),this.fileName=a.readData(this.fileNameLength),a.skip(c),this.compressedSize===-1||this.uncompressedSize===-1)throw new Error("Bug or corrupted zip : didn't get enough informations from the central directory (compressedSize === -1 || uncompressedSize === -1)");if(b=n(this.compressionMethod),null===b)throw new Error("Corrupted zip : compression "+f.pretty(this.compressionMethod)+" unknown (inner file : "+f.transformTo("string",this.fileName)+")");this.decompressed=new g(this.compressedSize,this.uncompressedSize,this.crc32,b,a.readData(this.compressedSize))},readCentralPart:function(a){this.versionMadeBy=a.readInt(2),a.skip(2),this.bitFlag=a.readInt(2),this.compressionMethod=a.readString(2),this.date=a.readDate(),this.crc32=a.readInt(4),this.compressedSize=a.readInt(4),this.uncompressedSize=a.readInt(4);var b=a.readInt(2);if(this.extraFieldsLength=a.readInt(2),this.fileCommentLength=a.readInt(2),this.diskNumberStart=a.readInt(2),this.internalFileAttributes=a.readInt(2),this.externalFileAttributes=a.readInt(4),this.localHeaderOffset=a.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");a.skip(b),this.readExtraFields(a),this.parseZIP64ExtraField(a),this.fileComment=a.readData(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var a=this.versionMadeBy>>8;this.dir=!!(16&this.externalFileAttributes),a===l&&(this.dosPermissions=63&this.externalFileAttributes),a===m&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||"/"!==this.fileNameStr.slice(-1)||(this.dir=!0)},parseZIP64ExtraField:function(a){if(this.extraFields[1]){var b=e(this.extraFields[1].value);this.uncompressedSize===f.MAX_VALUE_32BITS&&(this.uncompressedSize=b.readInt(8)),this.compressedSize===f.MAX_VALUE_32BITS&&(this.compressedSize=b.readInt(8)),this.localHeaderOffset===f.MAX_VALUE_32BITS&&(this.localHeaderOffset=b.readInt(8)),this.diskNumberStart===f.MAX_VALUE_32BITS&&(this.diskNumberStart=b.readInt(4))}},readExtraFields:function(a){var b,c,d,e=a.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});a.indexc;)b.push(arguments[c++]);return q[++p]=function(){h("function"==typeof a?a:Function(a),b)},d(p),p},n=function(a){delete q[a]},"process"==a("./_cof")(l)?d=function(a){l.nextTick(g(s,a,1))}:o?(e=new o,f=e.port2,e.port1.onmessage=t,d=g(f.postMessage,f,1)):k.addEventListener&&"function"==typeof postMessage&&!k.importScripts?(d=function(a){k.postMessage(a+"","*")},k.addEventListener("message",t,!1)):d=r in j("script")?function(a){i.appendChild(j("script"))[r]=function(){i.removeChild(this),s.call(a)}}:function(a){setTimeout(g(s,a,1),0)}),b.exports={set:m,clear:n}},{"./_cof":39,"./_ctx":41,"./_dom-create":43,"./_global":46,"./_html":48,"./_invoke":50}],55:[function(a,b,c){var d=a("./_is-object");b.exports=function(a,b){if(!d(a))return a;var c,e;if(b&&"function"==typeof(c=a.toString)&&!d(e=c.call(a)))return e;if("function"==typeof(c=a.valueOf)&&!d(e=c.call(a)))return e;if(!b&&"function"==typeof(c=a.toString)&&!d(e=c.call(a)))return e;throw TypeError("Can't convert object to primitive value")}},{"./_is-object":51}],56:[function(a,b,c){var d=a("./_export"),e=a("./_task");d(d.G+d.B,{setImmediate:e.set,clearImmediate:e.clear})},{"./_export":44,"./_task":54}],57:[function(a,b,c){(function(a){"use strict";function c(){k=!0;for(var a,b,c=l.length;c;){for(b=l,l=[],a=-1;++a0?b.windowBits=-b.windowBits:b.gzip&&b.windowBits>0&&b.windowBits<16&&(b.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new l,this.strm.avail_out=0;var c=h.deflateInit2(this.strm,b.level,b.method,b.windowBits,b.memLevel,b.strategy);if(c!==p)throw new Error(k[c]);if(b.header&&h.deflateSetHeader(this.strm,b.header),b.dictionary){var e;if(e="string"==typeof b.dictionary?j.string2buf(b.dictionary):"[object ArrayBuffer]"===m.call(b.dictionary)?new Uint8Array(b.dictionary):b.dictionary,c=h.deflateSetDictionary(this.strm,e),c!==p)throw new Error(k[c]);this._dict_set=!0}}function e(a,b){var c=new d(b);if(c.push(a,!0),c.err)throw c.msg||k[c.err];return c.result}function f(a,b){return b=b||{},b.raw=!0,e(a,b)}function g(a,b){return b=b||{},b.gzip=!0,e(a,b)}var h=a("./zlib/deflate"),i=a("./utils/common"),j=a("./utils/strings"),k=a("./zlib/messages"),l=a("./zlib/zstream"),m=Object.prototype.toString,n=0,o=4,p=0,q=1,r=2,s=-1,t=0,u=8;d.prototype.push=function(a,b){var c,d,e=this.strm,f=this.options.chunkSize;if(this.ended)return!1;d=b===~~b?b:b===!0?o:n,"string"==typeof a?e.input=j.string2buf(a):"[object ArrayBuffer]"===m.call(a)?e.input=new Uint8Array(a):e.input=a,e.next_in=0,e.avail_in=e.input.length;do{if(0===e.avail_out&&(e.output=new i.Buf8(f),e.next_out=0,e.avail_out=f),c=h.deflate(e,d),c!==q&&c!==p)return this.onEnd(c),this.ended=!0,!1;0!==e.avail_out&&(0!==e.avail_in||d!==o&&d!==r)||("string"===this.options.to?this.onData(j.buf2binstring(i.shrinkBuf(e.output,e.next_out))):this.onData(i.shrinkBuf(e.output,e.next_out)))}while((e.avail_in>0||0===e.avail_out)&&c!==q);return d===o?(c=h.deflateEnd(this.strm),this.onEnd(c),this.ended=!0,c===p):d!==r||(this.onEnd(p),e.avail_out=0,!0)},d.prototype.onData=function(a){this.chunks.push(a)},d.prototype.onEnd=function(a){a===p&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=i.flattenChunks(this.chunks)),this.chunks=[],this.err=a,this.msg=this.strm.msg},c.Deflate=d,c.deflate=e,c.deflateRaw=f,c.gzip=g},{"./utils/common":62,"./utils/strings":63,"./zlib/deflate":67,"./zlib/messages":72,"./zlib/zstream":74}],61:[function(a,b,c){"use strict";function d(a){if(!(this instanceof d))return new d(a);this.options=h.assign({chunkSize:16384,windowBits:0,to:""},a||{});var b=this.options;b.raw&&b.windowBits>=0&&b.windowBits<16&&(b.windowBits=-b.windowBits,0===b.windowBits&&(b.windowBits=-15)),!(b.windowBits>=0&&b.windowBits<16)||a&&a.windowBits||(b.windowBits+=32),b.windowBits>15&&b.windowBits<48&&0===(15&b.windowBits)&&(b.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new l,this.strm.avail_out=0;var c=g.inflateInit2(this.strm,b.windowBits);if(c!==j.Z_OK)throw new Error(k[c]);this.header=new m,g.inflateGetHeader(this.strm,this.header)}function e(a,b){var c=new d(b);if(c.push(a,!0),c.err)throw c.msg||k[c.err];return c.result}function f(a,b){return b=b||{},b.raw=!0,e(a,b)}var g=a("./zlib/inflate"),h=a("./utils/common"),i=a("./utils/strings"),j=a("./zlib/constants"),k=a("./zlib/messages"),l=a("./zlib/zstream"),m=a("./zlib/gzheader"),n=Object.prototype.toString;d.prototype.push=function(a,b){var c,d,e,f,k,l,m=this.strm,o=this.options.chunkSize,p=this.options.dictionary,q=!1;if(this.ended)return!1;d=b===~~b?b:b===!0?j.Z_FINISH:j.Z_NO_FLUSH,"string"==typeof a?m.input=i.binstring2buf(a):"[object ArrayBuffer]"===n.call(a)?m.input=new Uint8Array(a):m.input=a,m.next_in=0,m.avail_in=m.input.length;do{if(0===m.avail_out&&(m.output=new h.Buf8(o),m.next_out=0,m.avail_out=o),c=g.inflate(m,j.Z_NO_FLUSH),c===j.Z_NEED_DICT&&p&&(l="string"==typeof p?i.string2buf(p):"[object ArrayBuffer]"===n.call(p)?new Uint8Array(p):p,c=g.inflateSetDictionary(this.strm,l)),c===j.Z_BUF_ERROR&&q===!0&&(c=j.Z_OK,q=!1),c!==j.Z_STREAM_END&&c!==j.Z_OK)return this.onEnd(c),this.ended=!0,!1;m.next_out&&(0!==m.avail_out&&c!==j.Z_STREAM_END&&(0!==m.avail_in||d!==j.Z_FINISH&&d!==j.Z_SYNC_FLUSH)||("string"===this.options.to?(e=i.utf8border(m.output,m.next_out),f=m.next_out-e,k=i.buf2string(m.output,e),m.next_out=f,m.avail_out=o-f,f&&h.arraySet(m.output,m.output,e,f,0),this.onData(k)):this.onData(h.shrinkBuf(m.output,m.next_out)))),0===m.avail_in&&0===m.avail_out&&(q=!0)}while((m.avail_in>0||0===m.avail_out)&&c!==j.Z_STREAM_END);return c===j.Z_STREAM_END&&(d=j.Z_FINISH),d===j.Z_FINISH?(c=g.inflateEnd(this.strm),this.onEnd(c),this.ended=!0,c===j.Z_OK):d!==j.Z_SYNC_FLUSH||(this.onEnd(j.Z_OK),m.avail_out=0,!0)},d.prototype.onData=function(a){this.chunks.push(a)},d.prototype.onEnd=function(a){a===j.Z_OK&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=h.flattenChunks(this.chunks)),this.chunks=[],this.err=a,this.msg=this.strm.msg},c.Inflate=d,c.inflate=e,c.inflateRaw=f,c.ungzip=e},{"./utils/common":62,"./utils/strings":63,"./zlib/constants":65,"./zlib/gzheader":68,"./zlib/inflate":70,"./zlib/messages":72,"./zlib/zstream":74}],62:[function(a,b,c){"use strict";var d="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;c.assign=function(a){for(var b=Array.prototype.slice.call(arguments,1);b.length;){var c=b.shift();if(c){if("object"!=typeof c)throw new TypeError(c+"must be non-object");for(var d in c)c.hasOwnProperty(d)&&(a[d]=c[d])}}return a},c.shrinkBuf=function(a,b){return a.length===b?a:a.subarray?a.subarray(0,b):(a.length=b,a)};var e={arraySet:function(a,b,c,d,e){if(b.subarray&&a.subarray)return void a.set(b.subarray(c,c+d),e);for(var f=0;f=252?6:j>=248?5:j>=240?4:j>=224?3:j>=192?2:1;i[254]=i[254]=1,c.string2buf=function(a){var b,c,d,f,g,h=a.length,i=0;for(f=0;f>>6,b[g++]=128|63&c):c<65536?(b[g++]=224|c>>>12,b[g++]=128|c>>>6&63,b[g++]=128|63&c):(b[g++]=240|c>>>18,b[g++]=128|c>>>12&63,b[g++]=128|c>>>6&63,b[g++]=128|63&c);return b},c.buf2binstring=function(a){return d(a,a.length)},c.binstring2buf=function(a){for(var b=new e.Buf8(a.length),c=0,d=b.length;c4)j[e++]=65533,c+=g-1;else{for(f&=2===g?31:3===g?15:7;g>1&&c1?j[e++]=65533:f<65536?j[e++]=f:(f-=65536,j[e++]=55296|f>>10&1023,j[e++]=56320|1023&f)}return d(j,e)},c.utf8border=function(a,b){var c;for(b=b||a.length,b>a.length&&(b=a.length),c=b-1;c>=0&&128===(192&a[c]);)c--;return c<0?b:0===c?b:c+i[a[c]]>b?c:b}},{"./common":62}],64:[function(a,b,c){"use strict";function d(a,b,c,d){for(var e=65535&a|0,f=a>>>16&65535|0,g=0;0!==c;){g=c>2e3?2e3:c,c-=g;do e=e+b[d++]|0,f=f+e|0;while(--g);e%=65521,f%=65521}return e|f<<16|0; +}b.exports=d},{}],65:[function(a,b,c){"use strict";b.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],66:[function(a,b,c){"use strict";function d(){for(var a,b=[],c=0;c<256;c++){a=c;for(var d=0;d<8;d++)a=1&a?3988292384^a>>>1:a>>>1;b[c]=a}return b}function e(a,b,c,d){var e=f,g=d+c;a^=-1;for(var h=d;h>>8^e[255&(a^b[h])];return a^-1}var f=d();b.exports=e},{}],67:[function(a,b,c){"use strict";function d(a,b){return a.msg=I[b],b}function e(a){return(a<<1)-(a>4?9:0)}function f(a){for(var b=a.length;--b>=0;)a[b]=0}function g(a){var b=a.state,c=b.pending;c>a.avail_out&&(c=a.avail_out),0!==c&&(E.arraySet(a.output,b.pending_buf,b.pending_out,c,a.next_out),a.next_out+=c,b.pending_out+=c,a.total_out+=c,a.avail_out-=c,b.pending-=c,0===b.pending&&(b.pending_out=0))}function h(a,b){F._tr_flush_block(a,a.block_start>=0?a.block_start:-1,a.strstart-a.block_start,b),a.block_start=a.strstart,g(a.strm)}function i(a,b){a.pending_buf[a.pending++]=b}function j(a,b){a.pending_buf[a.pending++]=b>>>8&255,a.pending_buf[a.pending++]=255&b}function k(a,b,c,d){var e=a.avail_in;return e>d&&(e=d),0===e?0:(a.avail_in-=e,E.arraySet(b,a.input,a.next_in,e,c),1===a.state.wrap?a.adler=G(a.adler,b,e,c):2===a.state.wrap&&(a.adler=H(a.adler,b,e,c)),a.next_in+=e,a.total_in+=e,e)}function l(a,b){var c,d,e=a.max_chain_length,f=a.strstart,g=a.prev_length,h=a.nice_match,i=a.strstart>a.w_size-la?a.strstart-(a.w_size-la):0,j=a.window,k=a.w_mask,l=a.prev,m=a.strstart+ka,n=j[f+g-1],o=j[f+g];a.prev_length>=a.good_match&&(e>>=2),h>a.lookahead&&(h=a.lookahead);do if(c=b,j[c+g]===o&&j[c+g-1]===n&&j[c]===j[f]&&j[++c]===j[f+1]){f+=2,c++;do;while(j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&j[++f]===j[++c]&&fg){if(a.match_start=b,g=d,d>=h)break;n=j[f+g-1],o=j[f+g]}}while((b=l[b&k])>i&&0!==--e);return g<=a.lookahead?g:a.lookahead}function m(a){var b,c,d,e,f,g=a.w_size;do{if(e=a.window_size-a.lookahead-a.strstart,a.strstart>=g+(g-la)){E.arraySet(a.window,a.window,g,g,0),a.match_start-=g,a.strstart-=g,a.block_start-=g,c=a.hash_size,b=c;do d=a.head[--b],a.head[b]=d>=g?d-g:0;while(--c);c=g,b=c;do d=a.prev[--b],a.prev[b]=d>=g?d-g:0;while(--c);e+=g}if(0===a.strm.avail_in)break;if(c=k(a.strm,a.window,a.strstart+a.lookahead,e),a.lookahead+=c,a.lookahead+a.insert>=ja)for(f=a.strstart-a.insert,a.ins_h=a.window[f],a.ins_h=(a.ins_h<a.pending_buf_size-5&&(c=a.pending_buf_size-5);;){if(a.lookahead<=1){if(m(a),0===a.lookahead&&b===J)return ua;if(0===a.lookahead)break}a.strstart+=a.lookahead,a.lookahead=0;var d=a.block_start+c;if((0===a.strstart||a.strstart>=d)&&(a.lookahead=a.strstart-d,a.strstart=d,h(a,!1),0===a.strm.avail_out))return ua;if(a.strstart-a.block_start>=a.w_size-la&&(h(a,!1),0===a.strm.avail_out))return ua}return a.insert=0,b===M?(h(a,!0),0===a.strm.avail_out?wa:xa):a.strstart>a.block_start&&(h(a,!1),0===a.strm.avail_out)?ua:ua}function o(a,b){for(var c,d;;){if(a.lookahead=ja&&(a.ins_h=(a.ins_h<=ja)if(d=F._tr_tally(a,a.strstart-a.match_start,a.match_length-ja),a.lookahead-=a.match_length,a.match_length<=a.max_lazy_match&&a.lookahead>=ja){a.match_length--;do a.strstart++,a.ins_h=(a.ins_h<=ja&&(a.ins_h=(a.ins_h<4096)&&(a.match_length=ja-1)),a.prev_length>=ja&&a.match_length<=a.prev_length){e=a.strstart+a.lookahead-ja,d=F._tr_tally(a,a.strstart-1-a.prev_match,a.prev_length-ja),a.lookahead-=a.prev_length-1,a.prev_length-=2;do++a.strstart<=e&&(a.ins_h=(a.ins_h<=ja&&a.strstart>0&&(e=a.strstart-1,d=g[e],d===g[++e]&&d===g[++e]&&d===g[++e])){f=a.strstart+ka;do;while(d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&d===g[++e]&&ea.lookahead&&(a.match_length=a.lookahead)}if(a.match_length>=ja?(c=F._tr_tally(a,1,a.match_length-ja),a.lookahead-=a.match_length,a.strstart+=a.match_length,a.match_length=0):(c=F._tr_tally(a,0,a.window[a.strstart]),a.lookahead--,a.strstart++),c&&(h(a,!1),0===a.strm.avail_out))return ua}return a.insert=0,b===M?(h(a,!0),0===a.strm.avail_out?wa:xa):a.last_lit&&(h(a,!1),0===a.strm.avail_out)?ua:va}function r(a,b){for(var c;;){if(0===a.lookahead&&(m(a),0===a.lookahead)){if(b===J)return ua;break}if(a.match_length=0,c=F._tr_tally(a,0,a.window[a.strstart]),a.lookahead--,a.strstart++,c&&(h(a,!1),0===a.strm.avail_out))return ua}return a.insert=0,b===M?(h(a,!0),0===a.strm.avail_out?wa:xa):a.last_lit&&(h(a,!1),0===a.strm.avail_out)?ua:va}function s(a,b,c,d,e){this.good_length=a,this.max_lazy=b,this.nice_length=c,this.max_chain=d,this.func=e}function t(a){a.window_size=2*a.w_size,f(a.head),a.max_lazy_match=D[a.level].max_lazy,a.good_match=D[a.level].good_length,a.nice_match=D[a.level].nice_length,a.max_chain_length=D[a.level].max_chain,a.strstart=0,a.block_start=0,a.lookahead=0,a.insert=0,a.match_length=a.prev_length=ja-1,a.match_available=0,a.ins_h=0}function u(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=$,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new E.Buf16(2*ha),this.dyn_dtree=new E.Buf16(2*(2*fa+1)),this.bl_tree=new E.Buf16(2*(2*ga+1)),f(this.dyn_ltree),f(this.dyn_dtree),f(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new E.Buf16(ia+1),this.heap=new E.Buf16(2*ea+1),f(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new E.Buf16(2*ea+1),f(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function v(a){var b;return a&&a.state?(a.total_in=a.total_out=0,a.data_type=Z,b=a.state,b.pending=0,b.pending_out=0,b.wrap<0&&(b.wrap=-b.wrap),b.status=b.wrap?na:sa,a.adler=2===b.wrap?0:1,b.last_flush=J,F._tr_init(b),O):d(a,Q)}function w(a){var b=v(a);return b===O&&t(a.state),b}function x(a,b){return a&&a.state?2!==a.state.wrap?Q:(a.state.gzhead=b,O):Q}function y(a,b,c,e,f,g){if(!a)return Q;var h=1;if(b===T&&(b=6),e<0?(h=0,e=-e):e>15&&(h=2,e-=16),f<1||f>_||c!==$||e<8||e>15||b<0||b>9||g<0||g>X)return d(a,Q);8===e&&(e=9);var i=new u;return a.state=i,i.strm=a,i.wrap=h,i.gzhead=null,i.w_bits=e,i.w_size=1<N||b<0)return a?d(a,Q):Q;if(h=a.state,!a.output||!a.input&&0!==a.avail_in||h.status===ta&&b!==M)return d(a,0===a.avail_out?S:Q);if(h.strm=a,c=h.last_flush,h.last_flush=b,h.status===na)if(2===h.wrap)a.adler=0,i(h,31),i(h,139),i(h,8),h.gzhead?(i(h,(h.gzhead.text?1:0)+(h.gzhead.hcrc?2:0)+(h.gzhead.extra?4:0)+(h.gzhead.name?8:0)+(h.gzhead.comment?16:0)),i(h,255&h.gzhead.time),i(h,h.gzhead.time>>8&255),i(h,h.gzhead.time>>16&255),i(h,h.gzhead.time>>24&255),i(h,9===h.level?2:h.strategy>=V||h.level<2?4:0),i(h,255&h.gzhead.os),h.gzhead.extra&&h.gzhead.extra.length&&(i(h,255&h.gzhead.extra.length),i(h,h.gzhead.extra.length>>8&255)),h.gzhead.hcrc&&(a.adler=H(a.adler,h.pending_buf,h.pending,0)),h.gzindex=0,h.status=oa):(i(h,0),i(h,0),i(h,0),i(h,0),i(h,0),i(h,9===h.level?2:h.strategy>=V||h.level<2?4:0),i(h,ya),h.status=sa);else{var m=$+(h.w_bits-8<<4)<<8,n=-1;n=h.strategy>=V||h.level<2?0:h.level<6?1:6===h.level?2:3,m|=n<<6,0!==h.strstart&&(m|=ma),m+=31-m%31,h.status=sa,j(h,m),0!==h.strstart&&(j(h,a.adler>>>16),j(h,65535&a.adler)),a.adler=1}if(h.status===oa)if(h.gzhead.extra){for(k=h.pending;h.gzindex<(65535&h.gzhead.extra.length)&&(h.pending!==h.pending_buf_size||(h.gzhead.hcrc&&h.pending>k&&(a.adler=H(a.adler,h.pending_buf,h.pending-k,k)),g(a),k=h.pending,h.pending!==h.pending_buf_size));)i(h,255&h.gzhead.extra[h.gzindex]),h.gzindex++;h.gzhead.hcrc&&h.pending>k&&(a.adler=H(a.adler,h.pending_buf,h.pending-k,k)),h.gzindex===h.gzhead.extra.length&&(h.gzindex=0,h.status=pa)}else h.status=pa;if(h.status===pa)if(h.gzhead.name){k=h.pending;do{if(h.pending===h.pending_buf_size&&(h.gzhead.hcrc&&h.pending>k&&(a.adler=H(a.adler,h.pending_buf,h.pending-k,k)),g(a),k=h.pending,h.pending===h.pending_buf_size)){l=1;break}l=h.gzindexk&&(a.adler=H(a.adler,h.pending_buf,h.pending-k,k)),0===l&&(h.gzindex=0,h.status=qa)}else h.status=qa;if(h.status===qa)if(h.gzhead.comment){k=h.pending;do{if(h.pending===h.pending_buf_size&&(h.gzhead.hcrc&&h.pending>k&&(a.adler=H(a.adler,h.pending_buf,h.pending-k,k)),g(a),k=h.pending,h.pending===h.pending_buf_size)){l=1;break}l=h.gzindexk&&(a.adler=H(a.adler,h.pending_buf,h.pending-k,k)),0===l&&(h.status=ra)}else h.status=ra;if(h.status===ra&&(h.gzhead.hcrc?(h.pending+2>h.pending_buf_size&&g(a),h.pending+2<=h.pending_buf_size&&(i(h,255&a.adler),i(h,a.adler>>8&255),a.adler=0,h.status=sa)):h.status=sa),0!==h.pending){if(g(a),0===a.avail_out)return h.last_flush=-1,O}else if(0===a.avail_in&&e(b)<=e(c)&&b!==M)return d(a,S);if(h.status===ta&&0!==a.avail_in)return d(a,S);if(0!==a.avail_in||0!==h.lookahead||b!==J&&h.status!==ta){var o=h.strategy===V?r(h,b):h.strategy===W?q(h,b):D[h.level].func(h,b);if(o!==wa&&o!==xa||(h.status=ta),o===ua||o===wa)return 0===a.avail_out&&(h.last_flush=-1),O;if(o===va&&(b===K?F._tr_align(h):b!==N&&(F._tr_stored_block(h,0,0,!1),b===L&&(f(h.head),0===h.lookahead&&(h.strstart=0,h.block_start=0,h.insert=0))),g(a),0===a.avail_out))return h.last_flush=-1,O}return b!==M?O:h.wrap<=0?P:(2===h.wrap?(i(h,255&a.adler),i(h,a.adler>>8&255),i(h,a.adler>>16&255),i(h,a.adler>>24&255),i(h,255&a.total_in),i(h,a.total_in>>8&255),i(h,a.total_in>>16&255),i(h,a.total_in>>24&255)):(j(h,a.adler>>>16),j(h,65535&a.adler)),g(a),h.wrap>0&&(h.wrap=-h.wrap),0!==h.pending?O:P)}function B(a){var b;return a&&a.state?(b=a.state.status,b!==na&&b!==oa&&b!==pa&&b!==qa&&b!==ra&&b!==sa&&b!==ta?d(a,Q):(a.state=null,b===sa?d(a,R):O)):Q}function C(a,b){var c,d,e,g,h,i,j,k,l=b.length;if(!a||!a.state)return Q;if(c=a.state,g=c.wrap,2===g||1===g&&c.status!==na||c.lookahead)return Q;for(1===g&&(a.adler=G(a.adler,b,l,0)),c.wrap=0,l>=c.w_size&&(0===g&&(f(c.head),c.strstart=0,c.block_start=0,c.insert=0),k=new E.Buf8(c.w_size),E.arraySet(k,b,l-c.w_size,c.w_size,0),b=k,l=c.w_size),h=a.avail_in,i=a.next_in,j=a.input,a.avail_in=l,a.next_in=0,a.input=b,m(c);c.lookahead>=ja;){d=c.strstart,e=c.lookahead-(ja-1);do c.ins_h=(c.ins_h<>>24,p>>>=w,q-=w,w=v>>>16&255,0===w)C[h++]=65535&v;else{if(!(16&w)){if(0===(64&w)){v=r[(65535&v)+(p&(1<>>=w,q-=w),q<15&&(p+=B[f++]<>>24,p>>>=w,q-=w,w=v>>>16&255,!(16&w)){if(0===(64&w)){v=s[(65535&v)+(p&(1<k){a.msg="invalid distance too far back",c.mode=d;break a}if(p>>>=w,q-=w,w=h-i,y>w){if(w=y-w,w>m&&c.sane){a.msg="invalid distance too far back",c.mode=d;break a}if(z=0,A=o,0===n){if(z+=l-w,w2;)C[h++]=A[z++],C[h++]=A[z++],C[h++]=A[z++],x-=3;x&&(C[h++]=A[z++],x>1&&(C[h++]=A[z++]))}else{z=h-y;do C[h++]=C[z++],C[h++]=C[z++],C[h++]=C[z++],x-=3;while(x>2);x&&(C[h++]=C[z++],x>1&&(C[h++]=C[z++]))}break}}break}}while(f>3,f-=x,q-=x<<3,p&=(1<>>24&255)+(a>>>8&65280)+((65280&a)<<8)+((255&a)<<24)}function e(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new s.Buf16(320),this.work=new s.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function f(a){var b;return a&&a.state?(b=a.state,a.total_in=a.total_out=b.total=0,a.msg="",b.wrap&&(a.adler=1&b.wrap),b.mode=L,b.last=0,b.havedict=0,b.dmax=32768,b.head=null,b.hold=0,b.bits=0,b.lencode=b.lendyn=new s.Buf32(pa),b.distcode=b.distdyn=new s.Buf32(qa),b.sane=1,b.back=-1,D):G}function g(a){var b;return a&&a.state?(b=a.state,b.wsize=0,b.whave=0,b.wnext=0,f(a)):G}function h(a,b){var c,d;return a&&a.state?(d=a.state,b<0?(c=0,b=-b):(c=(b>>4)+1,b<48&&(b&=15)),b&&(b<8||b>15)?G:(null!==d.window&&d.wbits!==b&&(d.window=null),d.wrap=c,d.wbits=b,g(a))):G}function i(a,b){var c,d;return a?(d=new e,a.state=d,d.window=null,c=h(a,b),c!==D&&(a.state=null),c):G}function j(a){return i(a,sa)}function k(a){if(ta){var b;for(q=new s.Buf32(512),r=new s.Buf32(32),b=0;b<144;)a.lens[b++]=8;for(;b<256;)a.lens[b++]=9;for(;b<280;)a.lens[b++]=7;for(;b<288;)a.lens[b++]=8;for(w(y,a.lens,0,288,q,0,a.work,{bits:9}),b=0;b<32;)a.lens[b++]=5;w(z,a.lens,0,32,r,0,a.work,{bits:5}),ta=!1}a.lencode=q,a.lenbits=9,a.distcode=r,a.distbits=5}function l(a,b,c,d){var e,f=a.state;return null===f.window&&(f.wsize=1<=f.wsize?(s.arraySet(f.window,b,c-f.wsize,f.wsize,0),f.wnext=0,f.whave=f.wsize):(e=f.wsize-f.wnext,e>d&&(e=d),s.arraySet(f.window,b,c-d,e,f.wnext),d-=e,d?(s.arraySet(f.window,b,c-d,d,0),f.wnext=d,f.whave=f.wsize):(f.wnext+=e,f.wnext===f.wsize&&(f.wnext=0),f.whave>>8&255,c.check=u(c.check,Ba,2,0),m=0,n=0,c.mode=M;break}if(c.flags=0,c.head&&(c.head.done=!1),!(1&c.wrap)||(((255&m)<<8)+(m>>8))%31){a.msg="incorrect header check",c.mode=ma;break}if((15&m)!==K){a.msg="unknown compression method",c.mode=ma;break}if(m>>>=4,n-=4,wa=(15&m)+8,0===c.wbits)c.wbits=wa;else if(wa>c.wbits){a.msg="invalid window size",c.mode=ma;break}c.dmax=1<>8&1),512&c.flags&&(Ba[0]=255&m,Ba[1]=m>>>8&255,c.check=u(c.check,Ba,2,0)),m=0,n=0,c.mode=N;case N:for(;n<32;){if(0===i)break a;i--,m+=e[g++]<>>8&255,Ba[2]=m>>>16&255,Ba[3]=m>>>24&255,c.check=u(c.check,Ba,4,0)),m=0,n=0,c.mode=O;case O:for(;n<16;){if(0===i)break a;i--,m+=e[g++]<>8),512&c.flags&&(Ba[0]=255&m,Ba[1]=m>>>8&255,c.check=u(c.check,Ba,2,0)),m=0,n=0,c.mode=P;case P:if(1024&c.flags){for(;n<16;){if(0===i)break a;i--,m+=e[g++]<>>8&255,c.check=u(c.check,Ba,2,0)),m=0,n=0}else c.head&&(c.head.extra=null);c.mode=Q;case Q:if(1024&c.flags&&(q=c.length,q>i&&(q=i),q&&(c.head&&(wa=c.head.extra_len-c.length,c.head.extra||(c.head.extra=new Array(c.head.extra_len)),s.arraySet(c.head.extra,e,g,q,wa)),512&c.flags&&(c.check=u(c.check,e,q,g)),i-=q,g+=q,c.length-=q),c.length))break a;c.length=0,c.mode=R;case R:if(2048&c.flags){if(0===i)break a;q=0;do wa=e[g+q++],c.head&&wa&&c.length<65536&&(c.head.name+=String.fromCharCode(wa));while(wa&&q>9&1,c.head.done=!0),a.adler=c.check=0,c.mode=W;break;case U:for(;n<32;){if(0===i)break a;i--,m+=e[g++]<>>=7&n,n-=7&n,c.mode=ja;break}for(;n<3;){if(0===i)break a;i--,m+=e[g++]<>>=1,n-=1,3&m){case 0:c.mode=Y;break;case 1:if(k(c),c.mode=ca,b===C){m>>>=2,n-=2;break a}break;case 2:c.mode=_;break;case 3:a.msg="invalid block type",c.mode=ma}m>>>=2,n-=2;break;case Y:for(m>>>=7&n,n-=7&n;n<32;){if(0===i)break a;i--,m+=e[g++]<>>16^65535)){a.msg="invalid stored block lengths",c.mode=ma;break}if(c.length=65535&m,m=0,n=0,c.mode=Z,b===C)break a;case Z:c.mode=$;case $:if(q=c.length){if(q>i&&(q=i),q>j&&(q=j),0===q)break a;s.arraySet(f,e,g,q,h),i-=q,g+=q,j-=q,h+=q,c.length-=q;break}c.mode=W;break;case _:for(;n<14;){if(0===i)break a;i--,m+=e[g++]<>>=5,n-=5,c.ndist=(31&m)+1,m>>>=5,n-=5,c.ncode=(15&m)+4,m>>>=4,n-=4,c.nlen>286||c.ndist>30){a.msg="too many length or distance symbols",c.mode=ma;break}c.have=0,c.mode=aa;case aa:for(;c.have>>=3,n-=3}for(;c.have<19;)c.lens[Ca[c.have++]]=0;if(c.lencode=c.lendyn,c.lenbits=7,ya={bits:c.lenbits},xa=w(x,c.lens,0,19,c.lencode,0,c.work,ya),c.lenbits=ya.bits,xa){a.msg="invalid code lengths set",c.mode=ma;break}c.have=0,c.mode=ba;case ba:for(;c.have>>24,ra=Aa>>>16&255,sa=65535&Aa,!(qa<=n);){if(0===i)break a;i--,m+=e[g++]<>>=qa,n-=qa,c.lens[c.have++]=sa;else{if(16===sa){for(za=qa+2;n>>=qa,n-=qa,0===c.have){a.msg="invalid bit length repeat",c.mode=ma;break}wa=c.lens[c.have-1],q=3+(3&m),m>>>=2,n-=2}else if(17===sa){for(za=qa+3;n>>=qa,n-=qa,wa=0,q=3+(7&m),m>>>=3,n-=3}else{for(za=qa+7;n>>=qa,n-=qa,wa=0,q=11+(127&m),m>>>=7,n-=7}if(c.have+q>c.nlen+c.ndist){a.msg="invalid bit length repeat",c.mode=ma;break}for(;q--;)c.lens[c.have++]=wa}}if(c.mode===ma)break;if(0===c.lens[256]){a.msg="invalid code -- missing end-of-block",c.mode=ma;break}if(c.lenbits=9,ya={bits:c.lenbits},xa=w(y,c.lens,0,c.nlen,c.lencode,0,c.work,ya),c.lenbits=ya.bits,xa){a.msg="invalid literal/lengths set",c.mode=ma;break}if(c.distbits=6,c.distcode=c.distdyn,ya={bits:c.distbits},xa=w(z,c.lens,c.nlen,c.ndist,c.distcode,0,c.work,ya),c.distbits=ya.bits,xa){a.msg="invalid distances set",c.mode=ma;break}if(c.mode=ca,b===C)break a;case ca:c.mode=da;case da:if(i>=6&&j>=258){a.next_out=h,a.avail_out=j,a.next_in=g,a.avail_in=i,c.hold=m,c.bits=n,v(a,p),h=a.next_out,f=a.output,j=a.avail_out,g=a.next_in,e=a.input,i=a.avail_in,m=c.hold,n=c.bits,c.mode===W&&(c.back=-1);break}for(c.back=0;Aa=c.lencode[m&(1<>>24,ra=Aa>>>16&255,sa=65535&Aa,!(qa<=n);){if(0===i)break a;i--,m+=e[g++]<>ta)],qa=Aa>>>24,ra=Aa>>>16&255,sa=65535&Aa,!(ta+qa<=n);){if(0===i)break a;i--,m+=e[g++]<>>=ta,n-=ta,c.back+=ta}if(m>>>=qa,n-=qa,c.back+=qa,c.length=sa,0===ra){c.mode=ia;break}if(32&ra){c.back=-1,c.mode=W;break}if(64&ra){a.msg="invalid literal/length code",c.mode=ma;break}c.extra=15&ra,c.mode=ea;case ea:if(c.extra){for(za=c.extra;n>>=c.extra,n-=c.extra,c.back+=c.extra}c.was=c.length,c.mode=fa;case fa:for(;Aa=c.distcode[m&(1<>>24,ra=Aa>>>16&255,sa=65535&Aa,!(qa<=n);){if(0===i)break a;i--,m+=e[g++]<>ta)],qa=Aa>>>24,ra=Aa>>>16&255,sa=65535&Aa,!(ta+qa<=n);){if(0===i)break a;i--,m+=e[g++]<>>=ta,n-=ta,c.back+=ta}if(m>>>=qa,n-=qa,c.back+=qa,64&ra){a.msg="invalid distance code",c.mode=ma;break}c.offset=sa,c.extra=15&ra,c.mode=ga;case ga:if(c.extra){for(za=c.extra;n>>=c.extra,n-=c.extra,c.back+=c.extra}if(c.offset>c.dmax){a.msg="invalid distance too far back",c.mode=ma;break}c.mode=ha;case ha:if(0===j)break a;if(q=p-j,c.offset>q){if(q=c.offset-q,q>c.whave&&c.sane){a.msg="invalid distance too far back",c.mode=ma;break}q>c.wnext?(q-=c.wnext,r=c.wsize-q):r=c.wnext-q,q>c.length&&(q=c.length),pa=c.window}else pa=f,r=h-c.offset,q=c.length;q>j&&(q=j),j-=q,c.length-=q;do f[h++]=pa[r++];while(--q);0===c.length&&(c.mode=da);break;case ia:if(0===j)break a;f[h++]=c.length,j--,c.mode=da;break;case ja:if(c.wrap){for(;n<32;){if(0===i)break a;i--,m|=e[g++]<=1&&0===P[G];G--);if(H>G&&(H=G),0===G)return p[q++]=20971520,p[q++]=20971520,s.bits=1,0;for(F=1;F0&&(a===h||1!==G))return-1;for(Q[1]=0,D=1;Df||a===j&&L>g)return 1;for(;;){z=D-J,r[E]y?(A=R[S+r[E]],B=N[O+r[E]]):(A=96,B=0),t=1<>J)+u]=z<<24|A<<16|B|0;while(0!==u);for(t=1<>=1;if(0!==t?(M&=t-1,M+=t):M=0,E++,0===--P[D]){if(D===G)break;D=b[c+r[E]]}if(D>H&&(M&w)!==v){for(0===J&&(J=H),x+=F,I=D-J,K=1<f||a===j&&L>g)return 1;v=M&w,p[v]=H<<24|I<<16|x-q|0}}return 0!==M&&(p[x+M]=D-J<<24|64<<16|0),s.bits=H,0}},{"../utils/common":62}],72:[function(a,b,c){"use strict";b.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],73:[function(a,b,c){"use strict";function d(a){for(var b=a.length;--b>=0;)a[b]=0}function e(a,b,c,d,e){this.static_tree=a,this.extra_bits=b,this.extra_base=c,this.elems=d,this.max_length=e,this.has_stree=a&&a.length}function f(a,b){this.dyn_tree=a,this.max_code=0,this.stat_desc=b}function g(a){return a<256?ia[a]:ia[256+(a>>>7)]}function h(a,b){a.pending_buf[a.pending++]=255&b,a.pending_buf[a.pending++]=b>>>8&255}function i(a,b,c){a.bi_valid>X-c?(a.bi_buf|=b<>X-a.bi_valid,a.bi_valid+=c-X):(a.bi_buf|=b<>>=1,c<<=1;while(--b>0);return c>>>1}function l(a){16===a.bi_valid?(h(a,a.bi_buf),a.bi_buf=0,a.bi_valid=0):a.bi_valid>=8&&(a.pending_buf[a.pending++]=255&a.bi_buf,a.bi_buf>>=8,a.bi_valid-=8)}function m(a,b){var c,d,e,f,g,h,i=b.dyn_tree,j=b.max_code,k=b.stat_desc.static_tree,l=b.stat_desc.has_stree,m=b.stat_desc.extra_bits,n=b.stat_desc.extra_base,o=b.stat_desc.max_length,p=0;for(f=0;f<=W;f++)a.bl_count[f]=0;for(i[2*a.heap[a.heap_max]+1]=0, +c=a.heap_max+1;co&&(f=o,p++),i[2*d+1]=f,d>j||(a.bl_count[f]++,g=0,d>=n&&(g=m[d-n]),h=i[2*d],a.opt_len+=h*(f+g),l&&(a.static_len+=h*(k[2*d+1]+g)));if(0!==p){do{for(f=o-1;0===a.bl_count[f];)f--;a.bl_count[f]--,a.bl_count[f+1]+=2,a.bl_count[o]--,p-=2}while(p>0);for(f=o;0!==f;f--)for(d=a.bl_count[f];0!==d;)e=a.heap[--c],e>j||(i[2*e+1]!==f&&(a.opt_len+=(f-i[2*e+1])*i[2*e],i[2*e+1]=f),d--)}}function n(a,b,c){var d,e,f=new Array(W+1),g=0;for(d=1;d<=W;d++)f[d]=g=g+c[d-1]<<1;for(e=0;e<=b;e++){var h=a[2*e+1];0!==h&&(a[2*e]=k(f[h]++,h))}}function o(){var a,b,c,d,f,g=new Array(W+1);for(c=0,d=0;d>=7;d8?h(a,a.bi_buf):a.bi_valid>0&&(a.pending_buf[a.pending++]=a.bi_buf),a.bi_buf=0,a.bi_valid=0}function r(a,b,c,d){q(a),d&&(h(a,c),h(a,~c)),G.arraySet(a.pending_buf,a.window,b,c,a.pending),a.pending+=c}function s(a,b,c,d){var e=2*b,f=2*c;return a[e]>1;c>=1;c--)t(a,f,c);e=i;do c=a.heap[1],a.heap[1]=a.heap[a.heap_len--],t(a,f,1),d=a.heap[1],a.heap[--a.heap_max]=c,a.heap[--a.heap_max]=d,f[2*e]=f[2*c]+f[2*d],a.depth[e]=(a.depth[c]>=a.depth[d]?a.depth[c]:a.depth[d])+1,f[2*c+1]=f[2*d+1]=e,a.heap[1]=e++,t(a,f,1);while(a.heap_len>=2);a.heap[--a.heap_max]=a.heap[1],m(a,b),n(f,j,a.bl_count)}function w(a,b,c){var d,e,f=-1,g=b[1],h=0,i=7,j=4;for(0===g&&(i=138,j=3),b[2*(c+1)+1]=65535,d=0;d<=c;d++)e=g,g=b[2*(d+1)+1],++h=3&&0===a.bl_tree[2*ea[b]+1];b--);return a.opt_len+=3*(b+1)+5+5+4,b}function z(a,b,c,d){var e;for(i(a,b-257,5),i(a,c-1,5),i(a,d-4,4),e=0;e>>=1)if(1&c&&0!==a.dyn_ltree[2*b])return I;if(0!==a.dyn_ltree[18]||0!==a.dyn_ltree[20]||0!==a.dyn_ltree[26])return J;for(b=32;b0?(a.strm.data_type===K&&(a.strm.data_type=A(a)),v(a,a.l_desc),v(a,a.d_desc),g=y(a),e=a.opt_len+3+7>>>3,f=a.static_len+3+7>>>3,f<=e&&(e=f)):e=f=c+5,c+4<=e&&b!==-1?C(a,b,c,d):a.strategy===H||f===e?(i(a,(M<<1)+(d?1:0),3),u(a,ga,ha)):(i(a,(N<<1)+(d?1:0),3),z(a,a.l_desc.max_code+1,a.d_desc.max_code+1,g+1),u(a,a.dyn_ltree,a.dyn_dtree)),p(a),d&&q(a)}function F(a,b,c){return a.pending_buf[a.d_buf+2*a.last_lit]=b>>>8&255,a.pending_buf[a.d_buf+2*a.last_lit+1]=255&b,a.pending_buf[a.l_buf+a.last_lit]=255&c,a.last_lit++,0===b?a.dyn_ltree[2*c]++:(a.matches++,b--,a.dyn_ltree[2*(ja[c]+R+1)]++,a.dyn_dtree[2*g(b)]++),a.last_lit===a.lit_bufsize-1}var G=a("../utils/common"),H=4,I=0,J=1,K=2,L=0,M=1,N=2,O=3,P=258,Q=29,R=256,S=R+1+Q,T=30,U=19,V=2*S+1,W=15,X=16,Y=7,Z=256,$=16,_=17,aa=18,ba=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],ca=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],da=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],ea=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],fa=512,ga=new Array(2*(S+2));d(ga);var ha=new Array(2*T);d(ha);var ia=new Array(fa);d(ia);var ja=new Array(P-O+1);d(ja);var ka=new Array(Q);d(ka);var la=new Array(T);d(la);var ma,na,oa,pa=!1;c._tr_init=B,c._tr_stored_block=C,c._tr_flush_block=E,c._tr_tally=F,c._tr_align=D},{"../utils/common":62}],74:[function(a,b,c){"use strict";function d(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}b.exports=d},{}]},{},[10])(10)}); \ No newline at end of file diff --git a/testing/web-platform/tests/tools/wave/www/lib/keycodes.js b/testing/web-platform/tests/tools/wave/www/lib/keycodes.js new file mode 100644 index 0000000000..2d01b035ab --- /dev/null +++ b/testing/web-platform/tests/tools/wave/www/lib/keycodes.js @@ -0,0 +1,88 @@ +if (typeof KeyEvent != "undefined") { + if (typeof KeyEvent.VK_LEFT != "undefined") { + var VK_LEFT = KeyEvent.VK_LEFT; + var VK_UP = KeyEvent.VK_UP; + var VK_RIGHT = KeyEvent.VK_RIGHT; + var VK_DOWN = KeyEvent.VK_DOWN; + } + if (typeof KeyEvent.VK_ENTER != "undefined") { + var VK_ENTER = KeyEvent.VK_ENTER; + } + if (typeof KeyEvent.VK_RED != "undefined") { + var VK_RED = KeyEvent.VK_RED; + var VK_GREEN = KeyEvent.VK_GREEN; + var VK_YELLOW = KeyEvent.VK_YELLOW; + var VK_BLUE = KeyEvent.VK_BLUE; + } + if (typeof KeyEvent.VK_PLAY != "undefined") { + var VK_PLAY = KeyEvent.VK_PLAY; + var VK_PAUSE = KeyEvent.VK_PAUSE; + var VK_STOP = KeyEvent.VK_STOP; + } + if (typeof KeyEvent.VK_BACK != "undefined") { + var VK_BACK = KeyEvent.VK_BACK; + } + if (typeof KeyEvent.VK_0 != "undefined") { + var VK_0 = KeyEvent.VK_0; + var VK_1 = KeyEvent.VK_1; + var VK_2 = KeyEvent.VK_2; + var VK_3 = KeyEvent.VK_3; + var VK_4 = KeyEvent.VK_4; + var VK_5 = KeyEvent.VK_5; + var VK_6 = KeyEvent.VK_6; + var VK_7 = KeyEvent.VK_7; + var VK_8 = KeyEvent.VK_8; + var VK_9 = KeyEvent.VK_9; + } +} +if (typeof VK_LEFT == "undefined") { + var VK_LEFT = 132; + var VK_UP = 130; + var VK_RIGHT = 133; + var VK_DOWN = 131; +} +if (typeof VK_ENTER == "undefined") { + var VK_ENTER = 13; +} +if (typeof VK_RED == "undefined") { + var VK_RED = 403; + var VK_GREEN = 404; + var VK_YELLOW = 502; + var VK_BLUE = 406; +} +if (typeof VK_PLAY == "undefined") { + var VK_PLAY = 19; + var VK_PAUSE = 19; + var VK_STOP = 413; +} +if (typeof VK_BACK == "undefined") { + var VK_BACK = 0xa6; +} +if (typeof VK_0 == "undefined") { + var VK_0 = 48; + var VK_1 = 49; + var VK_2 = 50; + var VK_3 = 51; + var VK_4 = 52; + var VK_5 = 53; + var VK_6 = 54; + var VK_7 = 55; + var VK_8 = 56; + var VK_9 = 57; +} + +var NEXT_KEYS = [39, 133, 131]; +var PREV_KEYS = [37, 132, 130]; +var ACTION_KEYS = [13, 32]; + +if (typeof KeyEvent != "undefined") { + if (typeof KeyEvent.VK_LEFT != "undefined") { + PREV_KEYS.push(KeyEvent.VK_LEFT); + PREV_KEYS.push(KeyEvent.VK_UP); + NEXT_KEYS.push(KeyEvent.VK_RIGHT); + NEXT_KEYS.push(KeyEvent.VK_DOWN); + } + if (typeof KeyEvent.VK_ENTER != "undefined") { + ACTION_KEYS.push(KeyEvent.VK_ENTER); + } +} \ No newline at end of file diff --git a/testing/web-platform/tests/tools/wave/www/lib/qrcode.js b/testing/web-platform/tests/tools/wave/www/lib/qrcode.js new file mode 100644 index 0000000000..45e5d7b974 --- /dev/null +++ b/testing/web-platform/tests/tools/wave/www/lib/qrcode.js @@ -0,0 +1,1533 @@ +/** + * @fileoverview + * - Using the 'QRCode for Javascript library' + * - Fixed dataset of 'QRCode for Javascript library' for support full-spec. + * - this library has no dependencies. + * + * @author davidshimjs + * @see http://www.d-project.com/ + * @see http://jeromeetienne.github.com/jquery-qrcode/ + */ +var QRCode +;(function () { + // --------------------------------------------------------------------- + // QRCode for JavaScript + // + // Copyright (c) 2009 Kazuhiko Arase + // + // URL: http://www.d-project.com/ + // + // Licensed under the MIT license: + // http://www.opensource.org/licenses/mit-license.php + // + // The word "QR Code" is registered trademark of + // DENSO WAVE INCORPORATED + // http://www.denso-wave.com/qrcode/faqpatent-e.html + // + // --------------------------------------------------------------------- + function QR8bitByte (data) { + this.mode = QRMode.MODE_8BIT_BYTE + this.data = data + this.parsedData = [] + + // Added to support UTF-8 Characters + for (var i = 0, l = this.data.length; i < l; i++) { + var byteArray = [] + var code = this.data.charCodeAt(i) + + if (code > 0x10000) { + byteArray[0] = 0xf0 | ((code & 0x1c0000) >>> 18) + byteArray[1] = 0x80 | ((code & 0x3f000) >>> 12) + byteArray[2] = 0x80 | ((code & 0xfc0) >>> 6) + byteArray[3] = 0x80 | (code & 0x3f) + } else if (code > 0x800) { + byteArray[0] = 0xe0 | ((code & 0xf000) >>> 12) + byteArray[1] = 0x80 | ((code & 0xfc0) >>> 6) + byteArray[2] = 0x80 | (code & 0x3f) + } else if (code > 0x80) { + byteArray[0] = 0xc0 | ((code & 0x7c0) >>> 6) + byteArray[1] = 0x80 | (code & 0x3f) + } else { + byteArray[0] = code + } + + this.parsedData.push(byteArray) + } + + this.parsedData = Array.prototype.concat.apply([], this.parsedData) + + if (this.parsedData.length != this.data.length) { + this.parsedData.unshift(191) + this.parsedData.unshift(187) + this.parsedData.unshift(239) + } + } + + QR8bitByte.prototype = { + getLength: function (buffer) { + return this.parsedData.length + }, + write: function (buffer) { + for (var i = 0, l = this.parsedData.length; i < l; i++) { + buffer.put(this.parsedData[i], 8) + } + } + } + + function QRCodeModel (typeNumber, errorCorrectLevel) { + this.typeNumber = typeNumber + this.errorCorrectLevel = errorCorrectLevel + this.modules = null + this.moduleCount = 0 + this.dataCache = null + this.dataList = [] + } + + QRCodeModel.prototype = { + addData: function (data) { + var newData = new QR8bitByte(data) + this.dataList.push(newData) + this.dataCache = null + }, + isDark: function (row, col) { + if ( + row < 0 || + this.moduleCount <= row || + col < 0 || + this.moduleCount <= col + ) { + throw new Error(row + ',' + col) + } + return this.modules[row][col] + }, + getModuleCount: function () { + return this.moduleCount + }, + make: function () { + this.makeImpl(false, this.getBestMaskPattern()) + }, + makeImpl: function (test, maskPattern) { + this.moduleCount = this.typeNumber * 4 + 17 + this.modules = new Array(this.moduleCount) + for (var row = 0; row < this.moduleCount; row++) { + this.modules[row] = new Array(this.moduleCount) + for (var col = 0; col < this.moduleCount; col++) { + this.modules[row][col] = null + } + } + this.setupPositionProbePattern(0, 0) + this.setupPositionProbePattern(this.moduleCount - 7, 0) + this.setupPositionProbePattern(0, this.moduleCount - 7) + this.setupPositionAdjustPattern() + this.setupTimingPattern() + this.setupTypeInfo(test, maskPattern) + if (this.typeNumber >= 7) { + this.setupTypeNumber(test) + } + if (this.dataCache == null) { + this.dataCache = QRCodeModel.createData( + this.typeNumber, + this.errorCorrectLevel, + this.dataList + ) + } + this.mapData(this.dataCache, maskPattern) + }, + setupPositionProbePattern: function (row, col) { + for (var r = -1; r <= 7; r++) { + if (row + r <= -1 || this.moduleCount <= row + r) continue + for (var c = -1; c <= 7; c++) { + if (col + c <= -1 || this.moduleCount <= col + c) continue + if ( + (r >= 0 && r <= 6 && (c == 0 || c == 6)) || + (c >= 0 && c <= 6 && (r == 0 || r == 6)) || + (r >= 2 && r <= 4 && c >= 2 && c <= 4) + ) { + this.modules[row + r][col + c] = true + } else { + this.modules[row + r][col + c] = false + } + } + } + }, + getBestMaskPattern: function () { + var minLostPoint = 0 + var pattern = 0 + for (var i = 0; i < 8; i++) { + this.makeImpl(true, i) + var lostPoint = QRUtil.getLostPoint(this) + if (i == 0 || minLostPoint > lostPoint) { + minLostPoint = lostPoint + pattern = i + } + } + return pattern + }, + createMovieClip: function (target_mc, instance_name, depth) { + var qr_mc = target_mc.createEmptyMovieClip(instance_name, depth) + var cs = 1 + this.make() + for (var row = 0; row < this.modules.length; row++) { + var y = row * cs + for (var col = 0; col < this.modules[row].length; col++) { + var x = col * cs + var dark = this.modules[row][col] + if (dark) { + qr_mc.beginFill(0, 100) + qr_mc.moveTo(x, y) + qr_mc.lineTo(x + cs, y) + qr_mc.lineTo(x + cs, y + cs) + qr_mc.lineTo(x, y + cs) + qr_mc.endFill() + } + } + } + return qr_mc + }, + setupTimingPattern: function () { + for (var r = 8; r < this.moduleCount - 8; r++) { + if (this.modules[r][6] != null) { + continue + } + this.modules[r][6] = r % 2 == 0 + } + for (var c = 8; c < this.moduleCount - 8; c++) { + if (this.modules[6][c] != null) { + continue + } + this.modules[6][c] = c % 2 == 0 + } + }, + setupPositionAdjustPattern: function () { + var pos = QRUtil.getPatternPosition(this.typeNumber) + for (var i = 0; i < pos.length; i++) { + for (var j = 0; j < pos.length; j++) { + var row = pos[i] + var col = pos[j] + if (this.modules[row][col] != null) { + continue + } + for (var r = -2; r <= 2; r++) { + for (var c = -2; c <= 2; c++) { + if ( + r == -2 || + r == 2 || + c == -2 || + c == 2 || + (r == 0 && c == 0) + ) { + this.modules[row + r][col + c] = true + } else { + this.modules[row + r][col + c] = false + } + } + } + } + } + }, + setupTypeNumber: function (test) { + var bits = QRUtil.getBCHTypeNumber(this.typeNumber) + for (var i = 0; i < 18; i++) { + var mod = !test && ((bits >> i) & 1) == 1 + this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod + } + for (var i = 0; i < 18; i++) { + var mod = !test && ((bits >> i) & 1) == 1 + this.modules[i % 3 + this.moduleCount - 8 - 3][Math.floor(i / 3)] = mod + } + }, + setupTypeInfo: function (test, maskPattern) { + var data = (this.errorCorrectLevel << 3) | maskPattern + var bits = QRUtil.getBCHTypeInfo(data) + for (var i = 0; i < 15; i++) { + var mod = !test && ((bits >> i) & 1) == 1 + if (i < 6) { + this.modules[i][8] = mod + } else if (i < 8) { + this.modules[i + 1][8] = mod + } else { + this.modules[this.moduleCount - 15 + i][8] = mod + } + } + for (var i = 0; i < 15; i++) { + var mod = !test && ((bits >> i) & 1) == 1 + if (i < 8) { + this.modules[8][this.moduleCount - i - 1] = mod + } else if (i < 9) { + this.modules[8][15 - i - 1 + 1] = mod + } else { + this.modules[8][15 - i - 1] = mod + } + } + this.modules[this.moduleCount - 8][8] = !test + }, + mapData: function (data, maskPattern) { + var inc = -1 + var row = this.moduleCount - 1 + var bitIndex = 7 + var byteIndex = 0 + for (var col = this.moduleCount - 1; col > 0; col -= 2) { + if (col == 6) col-- + while (true) { + for (var c = 0; c < 2; c++) { + if (this.modules[row][col - c] == null) { + var dark = false + if (byteIndex < data.length) { + dark = ((data[byteIndex] >>> bitIndex) & 1) == 1 + } + var mask = QRUtil.getMask(maskPattern, row, col - c) + if (mask) { + dark = !dark + } + this.modules[row][col - c] = dark + bitIndex-- + if (bitIndex == -1) { + byteIndex++ + bitIndex = 7 + } + } + } + row += inc + if (row < 0 || this.moduleCount <= row) { + row -= inc + inc = -inc + break + } + } + } + } + } + QRCodeModel.PAD0 = 0xec + QRCodeModel.PAD1 = 0x11 + QRCodeModel.createData = function (typeNumber, errorCorrectLevel, dataList) { + var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel) + var buffer = new QRBitBuffer() + for (var i = 0; i < dataList.length; i++) { + var data = dataList[i] + buffer.put(data.mode, 4) + buffer.put( + data.getLength(), + QRUtil.getLengthInBits(data.mode, typeNumber) + ) + data.write(buffer) + } + var totalDataCount = 0 + for (var i = 0; i < rsBlocks.length; i++) { + totalDataCount += rsBlocks[i].dataCount + } + if (buffer.getLengthInBits() > totalDataCount * 8) { + throw new Error( + 'code length overflow. (' + + buffer.getLengthInBits() + + '>' + + totalDataCount * 8 + + ')' + ) + } + if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) { + buffer.put(0, 4) + } + while (buffer.getLengthInBits() % 8 != 0) { + buffer.putBit(false) + } + while (true) { + if (buffer.getLengthInBits() >= totalDataCount * 8) { + break + } + buffer.put(QRCodeModel.PAD0, 8) + if (buffer.getLengthInBits() >= totalDataCount * 8) { + break + } + buffer.put(QRCodeModel.PAD1, 8) + } + return QRCodeModel.createBytes(buffer, rsBlocks) + } + QRCodeModel.createBytes = function (buffer, rsBlocks) { + var offset = 0 + var maxDcCount = 0 + var maxEcCount = 0 + var dcdata = new Array(rsBlocks.length) + var ecdata = new Array(rsBlocks.length) + for (var r = 0; r < rsBlocks.length; r++) { + var dcCount = rsBlocks[r].dataCount + var ecCount = rsBlocks[r].totalCount - dcCount + maxDcCount = Math.max(maxDcCount, dcCount) + maxEcCount = Math.max(maxEcCount, ecCount) + dcdata[r] = new Array(dcCount) + for (var i = 0; i < dcdata[r].length; i++) { + dcdata[r][i] = 0xff & buffer.buffer[i + offset] + } + offset += dcCount + var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount) + var rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1) + var modPoly = rawPoly.mod(rsPoly) + ecdata[r] = new Array(rsPoly.getLength() - 1) + for (var i = 0; i < ecdata[r].length; i++) { + var modIndex = i + modPoly.getLength() - ecdata[r].length + ecdata[r][i] = modIndex >= 0 ? modPoly.get(modIndex) : 0 + } + } + var totalCodeCount = 0 + for (var i = 0; i < rsBlocks.length; i++) { + totalCodeCount += rsBlocks[i].totalCount + } + var data = new Array(totalCodeCount) + var index = 0 + for (var i = 0; i < maxDcCount; i++) { + for (var r = 0; r < rsBlocks.length; r++) { + if (i < dcdata[r].length) { + data[index++] = dcdata[r][i] + } + } + } + for (var i = 0; i < maxEcCount; i++) { + for (var r = 0; r < rsBlocks.length; r++) { + if (i < ecdata[r].length) { + data[index++] = ecdata[r][i] + } + } + } + return data + } + var QRMode = { + MODE_NUMBER: 1 << 0, + MODE_ALPHA_NUM: 1 << 1, + MODE_8BIT_BYTE: 1 << 2, + MODE_KANJI: 1 << 3 + } + var QRErrorCorrectLevel = { L: 1, M: 0, Q: 3, H: 2 } + var QRMaskPattern = { + PATTERN000: 0, + PATTERN001: 1, + PATTERN010: 2, + PATTERN011: 3, + PATTERN100: 4, + PATTERN101: 5, + PATTERN110: 6, + PATTERN111: 7 + } + var QRUtil = { + PATTERN_POSITION_TABLE: [ + [], + [6, 18], + [6, 22], + [6, 26], + [6, 30], + [6, 34], + [6, 22, 38], + [6, 24, 42], + [6, 26, 46], + [6, 28, 50], + [6, 30, 54], + [6, 32, 58], + [6, 34, 62], + [6, 26, 46, 66], + [6, 26, 48, 70], + [6, 26, 50, 74], + [6, 30, 54, 78], + [6, 30, 56, 82], + [6, 30, 58, 86], + [6, 34, 62, 90], + [6, 28, 50, 72, 94], + [6, 26, 50, 74, 98], + [6, 30, 54, 78, 102], + [6, 28, 54, 80, 106], + [6, 32, 58, 84, 110], + [6, 30, 58, 86, 114], + [6, 34, 62, 90, 118], + [6, 26, 50, 74, 98, 122], + [6, 30, 54, 78, 102, 126], + [6, 26, 52, 78, 104, 130], + [6, 30, 56, 82, 108, 134], + [6, 34, 60, 86, 112, 138], + [6, 30, 58, 86, 114, 142], + [6, 34, 62, 90, 118, 146], + [6, 30, 54, 78, 102, 126, 150], + [6, 24, 50, 76, 102, 128, 154], + [6, 28, 54, 80, 106, 132, 158], + [6, 32, 58, 84, 110, 136, 162], + [6, 26, 54, 82, 110, 138, 166], + [6, 30, 58, 86, 114, 142, 170] + ], + G15: + (1 << 10) | + (1 << 8) | + (1 << 5) | + (1 << 4) | + (1 << 2) | + (1 << 1) | + (1 << 0), + G18: + (1 << 12) | + (1 << 11) | + (1 << 10) | + (1 << 9) | + (1 << 8) | + (1 << 5) | + (1 << 2) | + (1 << 0), + G15_MASK: (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1), + getBCHTypeInfo: function (data) { + var d = data << 10 + while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) { + d ^= + QRUtil.G15 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15)) + } + return ((data << 10) | d) ^ QRUtil.G15_MASK + }, + getBCHTypeNumber: function (data) { + var d = data << 12 + while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) { + d ^= + QRUtil.G18 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18)) + } + return (data << 12) | d + }, + getBCHDigit: function (data) { + var digit = 0 + while (data != 0) { + digit++ + data >>>= 1 + } + return digit + }, + getPatternPosition: function (typeNumber) { + return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1] + }, + getMask: function (maskPattern, i, j) { + switch (maskPattern) { + case QRMaskPattern.PATTERN000: + return (i + j) % 2 == 0 + case QRMaskPattern.PATTERN001: + return i % 2 == 0 + case QRMaskPattern.PATTERN010: + return j % 3 == 0 + case QRMaskPattern.PATTERN011: + return (i + j) % 3 == 0 + case QRMaskPattern.PATTERN100: + return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0 + case QRMaskPattern.PATTERN101: + return (i * j) % 2 + (i * j) % 3 == 0 + case QRMaskPattern.PATTERN110: + return ((i * j) % 2 + (i * j) % 3) % 2 == 0 + case QRMaskPattern.PATTERN111: + return ((i * j) % 3 + (i + j) % 2) % 2 == 0 + default: + throw new Error('bad maskPattern:' + maskPattern) + } + }, + getErrorCorrectPolynomial: function (errorCorrectLength) { + var a = new QRPolynomial([1], 0) + for (var i = 0; i < errorCorrectLength; i++) { + a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0)) + } + return a + }, + getLengthInBits: function (mode, type) { + if (type >= 1 && type < 10) { + switch (mode) { + case QRMode.MODE_NUMBER: + return 10 + case QRMode.MODE_ALPHA_NUM: + return 9 + case QRMode.MODE_8BIT_BYTE: + return 8 + case QRMode.MODE_KANJI: + return 8 + default: + throw new Error('mode:' + mode) + } + } else if (type < 27) { + switch (mode) { + case QRMode.MODE_NUMBER: + return 12 + case QRMode.MODE_ALPHA_NUM: + return 11 + case QRMode.MODE_8BIT_BYTE: + return 16 + case QRMode.MODE_KANJI: + return 10 + default: + throw new Error('mode:' + mode) + } + } else if (type < 41) { + switch (mode) { + case QRMode.MODE_NUMBER: + return 14 + case QRMode.MODE_ALPHA_NUM: + return 13 + case QRMode.MODE_8BIT_BYTE: + return 16 + case QRMode.MODE_KANJI: + return 12 + default: + throw new Error('mode:' + mode) + } + } else { + throw new Error('type:' + type) + } + }, + getLostPoint: function (qrCode) { + var moduleCount = qrCode.getModuleCount() + var lostPoint = 0 + for (var row = 0; row < moduleCount; row++) { + for (var col = 0; col < moduleCount; col++) { + var sameCount = 0 + var dark = qrCode.isDark(row, col) + for (var r = -1; r <= 1; r++) { + if (row + r < 0 || moduleCount <= row + r) { + continue + } + for (var c = -1; c <= 1; c++) { + if (col + c < 0 || moduleCount <= col + c) { + continue + } + if (r == 0 && c == 0) { + continue + } + if (dark == qrCode.isDark(row + r, col + c)) { + sameCount++ + } + } + } + if (sameCount > 5) { + lostPoint += 3 + sameCount - 5 + } + } + } + for (var row = 0; row < moduleCount - 1; row++) { + for (var col = 0; col < moduleCount - 1; col++) { + var count = 0 + if (qrCode.isDark(row, col)) count++ + if (qrCode.isDark(row + 1, col)) count++ + if (qrCode.isDark(row, col + 1)) count++ + if (qrCode.isDark(row + 1, col + 1)) count++ + if (count == 0 || count == 4) { + lostPoint += 3 + } + } + } + for (var row = 0; row < moduleCount; row++) { + for (var col = 0; col < moduleCount - 6; col++) { + if ( + qrCode.isDark(row, col) && + !qrCode.isDark(row, col + 1) && + qrCode.isDark(row, col + 2) && + qrCode.isDark(row, col + 3) && + qrCode.isDark(row, col + 4) && + !qrCode.isDark(row, col + 5) && + qrCode.isDark(row, col + 6) + ) { + lostPoint += 40 + } + } + } + for (var col = 0; col < moduleCount; col++) { + for (var row = 0; row < moduleCount - 6; row++) { + if ( + qrCode.isDark(row, col) && + !qrCode.isDark(row + 1, col) && + qrCode.isDark(row + 2, col) && + qrCode.isDark(row + 3, col) && + qrCode.isDark(row + 4, col) && + !qrCode.isDark(row + 5, col) && + qrCode.isDark(row + 6, col) + ) { + lostPoint += 40 + } + } + } + var darkCount = 0 + for (var col = 0; col < moduleCount; col++) { + for (var row = 0; row < moduleCount; row++) { + if (qrCode.isDark(row, col)) { + darkCount++ + } + } + } + var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5 + lostPoint += ratio * 10 + return lostPoint + } + } + var QRMath = { + glog: function (n) { + if (n < 1) { + throw new Error('glog(' + n + ')') + } + return QRMath.LOG_TABLE[n] + }, + gexp: function (n) { + while (n < 0) { + n += 255 + } + while (n >= 256) { + n -= 255 + } + return QRMath.EXP_TABLE[n] + }, + EXP_TABLE: new Array(256), + LOG_TABLE: new Array(256) + } + for (var i = 0; i < 8; i++) { + QRMath.EXP_TABLE[i] = 1 << i + } + for (var i = 8; i < 256; i++) { + QRMath.EXP_TABLE[i] = + QRMath.EXP_TABLE[i - 4] ^ + QRMath.EXP_TABLE[i - 5] ^ + QRMath.EXP_TABLE[i - 6] ^ + QRMath.EXP_TABLE[i - 8] + } + for (var i = 0; i < 255; i++) { + QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]] = i + } + function QRPolynomial (num, shift) { + if (num.length == undefined) { + throw new Error(num.length + '/' + shift) + } + var offset = 0 + while (offset < num.length && num[offset] == 0) { + offset++ + } + this.num = new Array(num.length - offset + shift) + for (var i = 0; i < num.length - offset; i++) { + this.num[i] = num[i + offset] + } + } + QRPolynomial.prototype = { + get: function (index) { + return this.num[index] + }, + getLength: function () { + return this.num.length + }, + multiply: function (e) { + var num = new Array(this.getLength() + e.getLength() - 1) + for (var i = 0; i < this.getLength(); i++) { + for (var j = 0; j < e.getLength(); j++) { + num[i + j] ^= QRMath.gexp( + QRMath.glog(this.get(i)) + QRMath.glog(e.get(j)) + ) + } + } + return new QRPolynomial(num, 0) + }, + mod: function (e) { + if (this.getLength() - e.getLength() < 0) { + return this + } + var ratio = QRMath.glog(this.get(0)) - QRMath.glog(e.get(0)) + var num = new Array(this.getLength()) + for (var i = 0; i < this.getLength(); i++) { + num[i] = this.get(i) + } + for (var i = 0; i < e.getLength(); i++) { + num[i] ^= QRMath.gexp(QRMath.glog(e.get(i)) + ratio) + } + return new QRPolynomial(num, 0).mod(e) + } + } + function QRRSBlock (totalCount, dataCount) { + this.totalCount = totalCount + this.dataCount = dataCount + } + QRRSBlock.RS_BLOCK_TABLE = [ + [1, 26, 19], + [1, 26, 16], + [1, 26, 13], + [1, 26, 9], + [1, 44, 34], + [1, 44, 28], + [1, 44, 22], + [1, 44, 16], + [1, 70, 55], + [1, 70, 44], + [2, 35, 17], + [2, 35, 13], + [1, 100, 80], + [2, 50, 32], + [2, 50, 24], + [4, 25, 9], + [1, 134, 108], + [2, 67, 43], + [2, 33, 15, 2, 34, 16], + [2, 33, 11, 2, 34, 12], + [2, 86, 68], + [4, 43, 27], + [4, 43, 19], + [4, 43, 15], + [2, 98, 78], + [4, 49, 31], + [2, 32, 14, 4, 33, 15], + [4, 39, 13, 1, 40, 14], + [2, 121, 97], + [2, 60, 38, 2, 61, 39], + [4, 40, 18, 2, 41, 19], + [4, 40, 14, 2, 41, 15], + [2, 146, 116], + [3, 58, 36, 2, 59, 37], + [4, 36, 16, 4, 37, 17], + [4, 36, 12, 4, 37, 13], + [2, 86, 68, 2, 87, 69], + [4, 69, 43, 1, 70, 44], + [6, 43, 19, 2, 44, 20], + [6, 43, 15, 2, 44, 16], + [4, 101, 81], + [1, 80, 50, 4, 81, 51], + [4, 50, 22, 4, 51, 23], + [3, 36, 12, 8, 37, 13], + [2, 116, 92, 2, 117, 93], + [6, 58, 36, 2, 59, 37], + [4, 46, 20, 6, 47, 21], + [7, 42, 14, 4, 43, 15], + [4, 133, 107], + [8, 59, 37, 1, 60, 38], + [8, 44, 20, 4, 45, 21], + [12, 33, 11, 4, 34, 12], + [3, 145, 115, 1, 146, 116], + [4, 64, 40, 5, 65, 41], + [11, 36, 16, 5, 37, 17], + [11, 36, 12, 5, 37, 13], + [5, 109, 87, 1, 110, 88], + [5, 65, 41, 5, 66, 42], + [5, 54, 24, 7, 55, 25], + [11, 36, 12], + [5, 122, 98, 1, 123, 99], + [7, 73, 45, 3, 74, 46], + [15, 43, 19, 2, 44, 20], + [3, 45, 15, 13, 46, 16], + [1, 135, 107, 5, 136, 108], + [10, 74, 46, 1, 75, 47], + [1, 50, 22, 15, 51, 23], + [2, 42, 14, 17, 43, 15], + [5, 150, 120, 1, 151, 121], + [9, 69, 43, 4, 70, 44], + [17, 50, 22, 1, 51, 23], + [2, 42, 14, 19, 43, 15], + [3, 141, 113, 4, 142, 114], + [3, 70, 44, 11, 71, 45], + [17, 47, 21, 4, 48, 22], + [9, 39, 13, 16, 40, 14], + [3, 135, 107, 5, 136, 108], + [3, 67, 41, 13, 68, 42], + [15, 54, 24, 5, 55, 25], + [15, 43, 15, 10, 44, 16], + [4, 144, 116, 4, 145, 117], + [17, 68, 42], + [17, 50, 22, 6, 51, 23], + [19, 46, 16, 6, 47, 17], + [2, 139, 111, 7, 140, 112], + [17, 74, 46], + [7, 54, 24, 16, 55, 25], + [34, 37, 13], + [4, 151, 121, 5, 152, 122], + [4, 75, 47, 14, 76, 48], + [11, 54, 24, 14, 55, 25], + [16, 45, 15, 14, 46, 16], + [6, 147, 117, 4, 148, 118], + [6, 73, 45, 14, 74, 46], + [11, 54, 24, 16, 55, 25], + [30, 46, 16, 2, 47, 17], + [8, 132, 106, 4, 133, 107], + [8, 75, 47, 13, 76, 48], + [7, 54, 24, 22, 55, 25], + [22, 45, 15, 13, 46, 16], + [10, 142, 114, 2, 143, 115], + [19, 74, 46, 4, 75, 47], + [28, 50, 22, 6, 51, 23], + [33, 46, 16, 4, 47, 17], + [8, 152, 122, 4, 153, 123], + [22, 73, 45, 3, 74, 46], + [8, 53, 23, 26, 54, 24], + [12, 45, 15, 28, 46, 16], + [3, 147, 117, 10, 148, 118], + [3, 73, 45, 23, 74, 46], + [4, 54, 24, 31, 55, 25], + [11, 45, 15, 31, 46, 16], + [7, 146, 116, 7, 147, 117], + [21, 73, 45, 7, 74, 46], + [1, 53, 23, 37, 54, 24], + [19, 45, 15, 26, 46, 16], + [5, 145, 115, 10, 146, 116], + [19, 75, 47, 10, 76, 48], + [15, 54, 24, 25, 55, 25], + [23, 45, 15, 25, 46, 16], + [13, 145, 115, 3, 146, 116], + [2, 74, 46, 29, 75, 47], + [42, 54, 24, 1, 55, 25], + [23, 45, 15, 28, 46, 16], + [17, 145, 115], + [10, 74, 46, 23, 75, 47], + [10, 54, 24, 35, 55, 25], + [19, 45, 15, 35, 46, 16], + [17, 145, 115, 1, 146, 116], + [14, 74, 46, 21, 75, 47], + [29, 54, 24, 19, 55, 25], + [11, 45, 15, 46, 46, 16], + [13, 145, 115, 6, 146, 116], + [14, 74, 46, 23, 75, 47], + [44, 54, 24, 7, 55, 25], + [59, 46, 16, 1, 47, 17], + [12, 151, 121, 7, 152, 122], + [12, 75, 47, 26, 76, 48], + [39, 54, 24, 14, 55, 25], + [22, 45, 15, 41, 46, 16], + [6, 151, 121, 14, 152, 122], + [6, 75, 47, 34, 76, 48], + [46, 54, 24, 10, 55, 25], + [2, 45, 15, 64, 46, 16], + [17, 152, 122, 4, 153, 123], + [29, 74, 46, 14, 75, 47], + [49, 54, 24, 10, 55, 25], + [24, 45, 15, 46, 46, 16], + [4, 152, 122, 18, 153, 123], + [13, 74, 46, 32, 75, 47], + [48, 54, 24, 14, 55, 25], + [42, 45, 15, 32, 46, 16], + [20, 147, 117, 4, 148, 118], + [40, 75, 47, 7, 76, 48], + [43, 54, 24, 22, 55, 25], + [10, 45, 15, 67, 46, 16], + [19, 148, 118, 6, 149, 119], + [18, 75, 47, 31, 76, 48], + [34, 54, 24, 34, 55, 25], + [20, 45, 15, 61, 46, 16] + ] + QRRSBlock.getRSBlocks = function (typeNumber, errorCorrectLevel) { + var rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel) + if (rsBlock == undefined) { + throw new Error( + 'bad rs block @ typeNumber:' + + typeNumber + + '/errorCorrectLevel:' + + errorCorrectLevel + ) + } + var length = rsBlock.length / 3 + var list = [] + for (var i = 0; i < length; i++) { + var count = rsBlock[i * 3 + 0] + var totalCount = rsBlock[i * 3 + 1] + var dataCount = rsBlock[i * 3 + 2] + for (var j = 0; j < count; j++) { + list.push(new QRRSBlock(totalCount, dataCount)) + } + } + return list + } + QRRSBlock.getRsBlockTable = function (typeNumber, errorCorrectLevel) { + switch (errorCorrectLevel) { + case QRErrorCorrectLevel.L: + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0] + case QRErrorCorrectLevel.M: + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1] + case QRErrorCorrectLevel.Q: + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2] + case QRErrorCorrectLevel.H: + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3] + default: + return undefined + } + } + function QRBitBuffer () { + this.buffer = [] + this.length = 0 + } + QRBitBuffer.prototype = { + get: function (index) { + var bufIndex = Math.floor(index / 8) + return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) == 1 + }, + put: function (num, length) { + for (var i = 0; i < length; i++) { + this.putBit(((num >>> (length - i - 1)) & 1) == 1) + } + }, + getLengthInBits: function () { + return this.length + }, + putBit: function (bit) { + var bufIndex = Math.floor(this.length / 8) + if (this.buffer.length <= bufIndex) { + this.buffer.push(0) + } + if (bit) { + this.buffer[bufIndex] |= 0x80 >>> (this.length % 8) + } + this.length++ + } + } + var QRCodeLimitLength = [ + [17, 14, 11, 7], + [32, 26, 20, 14], + [53, 42, 32, 24], + [78, 62, 46, 34], + [106, 84, 60, 44], + [134, 106, 74, 58], + [154, 122, 86, 64], + [192, 152, 108, 84], + [230, 180, 130, 98], + [271, 213, 151, 119], + [321, 251, 177, 137], + [367, 287, 203, 155], + [425, 331, 241, 177], + [458, 362, 258, 194], + [520, 412, 292, 220], + [586, 450, 322, 250], + [644, 504, 364, 280], + [718, 560, 394, 310], + [792, 624, 442, 338], + [858, 666, 482, 382], + [929, 711, 509, 403], + [1003, 779, 565, 439], + [1091, 857, 611, 461], + [1171, 911, 661, 511], + [1273, 997, 715, 535], + [1367, 1059, 751, 593], + [1465, 1125, 805, 625], + [1528, 1190, 868, 658], + [1628, 1264, 908, 698], + [1732, 1370, 982, 742], + [1840, 1452, 1030, 790], + [1952, 1538, 1112, 842], + [2068, 1628, 1168, 898], + [2188, 1722, 1228, 958], + [2303, 1809, 1283, 983], + [2431, 1911, 1351, 1051], + [2563, 1989, 1423, 1093], + [2699, 2099, 1499, 1139], + [2809, 2213, 1579, 1219], + [2953, 2331, 1663, 1273] + ] + + function _isSupportCanvas () { + return typeof CanvasRenderingContext2D !== 'undefined' + } + + // android 2.x doesn't support Data-URI spec + function _getAndroid () { + var android = false + var sAgent = navigator.userAgent + + if (/android/i.test(sAgent)) { + // android + android = true + var aMat = sAgent.toString().match(/android ([0-9]\.[0-9])/i) + + if (aMat && aMat[1]) { + android = parseFloat(aMat[1]) + } + } + + return android + } + + var svgDrawer = (function () { + var Drawing = function (el, htOption) { + this._el = el + this._htOption = htOption + } + + Drawing.prototype.draw = function (oQRCode) { + var _htOption = this._htOption + var _el = this._el + var nCount = oQRCode.getModuleCount() + var nWidth = Math.floor(_htOption.width / nCount) + var nHeight = Math.floor(_htOption.height / nCount) + + this.clear() + + function makeSVG (tag, attrs) { + var el = document.createElementNS('http://www.w3.org/2000/svg', tag) + for (var k in attrs) { + if (attrs.hasOwnProperty(k)) el.setAttribute(k, attrs[k]) + } + return el + } + + var svg = makeSVG('svg', { + viewBox: '0 0 ' + String(nCount) + ' ' + String(nCount), + width: '100%', + height: '100%', + fill: _htOption.colorLight + }) + svg.setAttributeNS( + 'http://www.w3.org/2000/xmlns/', + 'xmlns:xlink', + 'http://www.w3.org/1999/xlink' + ) + _el.appendChild(svg) + + svg.appendChild( + makeSVG('rect', { + fill: _htOption.colorLight, + width: '100%', + height: '100%' + }) + ) + svg.appendChild( + makeSVG('rect', { + fill: _htOption.colorDark, + width: '1', + height: '1', + id: 'template' + }) + ) + + for (var row = 0; row < nCount; row++) { + for (var col = 0; col < nCount; col++) { + if (oQRCode.isDark(row, col)) { + var child = makeSVG('use', { x: String(col), y: String(row) }) + child.setAttributeNS( + 'http://www.w3.org/1999/xlink', + 'href', + '#template' + ) + svg.appendChild(child) + } + } + } + } + Drawing.prototype.clear = function () { + while (this._el.hasChildNodes()) this._el.removeChild(this._el.lastChild) + } + return Drawing + })() + + var useSVG = document.documentElement.tagName.toLowerCase() === 'svg' + + // Drawing in DOM by using Table tag + var Drawing = useSVG + ? svgDrawer + : !_isSupportCanvas() + ? (function () { + var Drawing = function (el, htOption) { + this._el = el + this._htOption = htOption + } + + /** + * Draw the QRCode + * + * @param {QRCode} oQRCode + */ + Drawing.prototype.draw = function (oQRCode) { + var _htOption = this._htOption + var _el = this._el + var nCount = oQRCode.getModuleCount() + var nWidth = Math.floor(_htOption.width / nCount) + var nHeight = Math.floor(_htOption.height / nCount) + var aHTML = [''] + + for (var row = 0; row < nCount; row++) { + aHTML.push('') + + for (var col = 0; col < nCount; col++) { + aHTML.push( + '' + ) + } + + aHTML.push('') + } + + aHTML.push('
') + _el.innerHTML = aHTML.join('') + + // Fix the margin values as real size. + var elTable = _el.childNodes[0] + var nLeftMarginTable = (_htOption.width - elTable.offsetWidth) / 2 + var nTopMarginTable = (_htOption.height - elTable.offsetHeight) / 2 + + if (nLeftMarginTable > 0 && nTopMarginTable > 0) { + elTable.style.margin = + nTopMarginTable + 'px ' + nLeftMarginTable + 'px' + } + } + + /** + * Clear the QRCode + */ + Drawing.prototype.clear = function () { + this._el.innerHTML = '' + } + + return Drawing + })() + : (function () { + // Drawing in Canvas + function _onMakeImage () { + this._elImage.src = this._elCanvas.toDataURL('image/png') + this._elImage.style.display = 'block' + this._elCanvas.style.display = 'none' + } + + // Android 2.1 bug workaround + // http://code.google.com/p/android/issues/detail?id=5141 + if (this._android && this._android <= 2.1) { + var factor = 1 / window.devicePixelRatio + var drawImage = CanvasRenderingContext2D.prototype.drawImage + CanvasRenderingContext2D.prototype.drawImage = function ( + image, + sx, + sy, + sw, + sh, + dx, + dy, + dw, + dh + ) { + if ('nodeName' in image && /img/i.test(image.nodeName)) { + for (var i = arguments.length - 1; i >= 1; i--) { + arguments[i] = arguments[i] * factor + } + } else if (typeof dw === 'undefined') { + arguments[1] *= factor + arguments[2] *= factor + arguments[3] *= factor + arguments[4] *= factor + } + + drawImage.apply(this, arguments) + } + } + + /** + * Check whether the user's browser supports Data URI or not + * + * @private + * @param {Function} fSuccess Occurs if it supports Data URI + * @param {Function} fFail Occurs if it doesn't support Data URI + */ + function _safeSetDataURI (fSuccess, fFail) { + var self = this + self._fFail = fFail + self._fSuccess = fSuccess + + // Check it just once + if (self._bSupportDataURI === null) { + var el = document.createElement('img') + var fOnError = function () { + self._bSupportDataURI = false + + if (self._fFail) { + self._fFail.call(self) + } + } + var fOnSuccess = function () { + self._bSupportDataURI = true + + if (self._fSuccess) { + self._fSuccess.call(self) + } + } + + el.onabort = fOnError + el.onerror = fOnError + el.onload = fOnSuccess + el.src = + 'data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==' // the Image contains 1px data. + } else if (self._bSupportDataURI === true && self._fSuccess) { + self._fSuccess.call(self) + } else if (self._bSupportDataURI === false && self._fFail) { + self._fFail.call(self) + } + } + + /** + * Drawing QRCode by using canvas + * + * @constructor + * @param {HTMLElement} el + * @param {Object} htOption QRCode Options + */ + var Drawing = function (el, htOption) { + this._bIsPainted = false + this._android = _getAndroid() + + this._htOption = htOption + this._elCanvas = document.createElement('canvas') + this._elCanvas.width = htOption.width + this._elCanvas.height = htOption.height + el.appendChild(this._elCanvas) + this._el = el + this._oContext = this._elCanvas.getContext('2d') + this._bIsPainted = false + this._elImage = document.createElement('img') + this._elImage.alt = 'Scan me!' + this._elImage.style.display = 'none' + this._el.appendChild(this._elImage) + this._bSupportDataURI = null + } + + /** + * Draw the QRCode + * + * @param {QRCode} oQRCode + */ + Drawing.prototype.draw = function (oQRCode) { + var _elImage = this._elImage + var _oContext = this._oContext + var _htOption = this._htOption + + var nCount = oQRCode.getModuleCount() + var nWidth = _htOption.width / nCount + var nHeight = _htOption.height / nCount + var nRoundedWidth = Math.round(nWidth) + var nRoundedHeight = Math.round(nHeight) + + _elImage.style.display = 'none' + this.clear() + + for (var row = 0; row < nCount; row++) { + for (var col = 0; col < nCount; col++) { + var bIsDark = oQRCode.isDark(row, col) + var nLeft = col * nWidth + var nTop = row * nHeight + _oContext.strokeStyle = bIsDark + ? _htOption.colorDark + : _htOption.colorLight + _oContext.lineWidth = 1 + _oContext.fillStyle = bIsDark + ? _htOption.colorDark + : _htOption.colorLight + _oContext.fillRect(nLeft, nTop, nWidth, nHeight) + + // 안티 앨리어싱 방지 처리 + _oContext.strokeRect( + Math.floor(nLeft) + 0.5, + Math.floor(nTop) + 0.5, + nRoundedWidth, + nRoundedHeight + ) + + _oContext.strokeRect( + Math.ceil(nLeft) - 0.5, + Math.ceil(nTop) - 0.5, + nRoundedWidth, + nRoundedHeight + ) + } + } + + this._bIsPainted = true + } + + /** + * Make the image from Canvas if the browser supports Data URI. + */ + Drawing.prototype.makeImage = function () { + if (this._bIsPainted) { + _safeSetDataURI.call(this, _onMakeImage) + } + } + + /** + * Return whether the QRCode is painted or not + * + * @return {Boolean} + */ + Drawing.prototype.isPainted = function () { + return this._bIsPainted + } + + /** + * Clear the QRCode + */ + Drawing.prototype.clear = function () { + this._oContext.clearRect( + 0, + 0, + this._elCanvas.width, + this._elCanvas.height + ) + this._bIsPainted = false + } + + /** + * @private + * @param {Number} nNumber + */ + Drawing.prototype.round = function (nNumber) { + if (!nNumber) { + return nNumber + } + + return Math.floor(nNumber * 1000) / 1000 + } + + return Drawing + })() + + /** + * Get the type by string length + * + * @private + * @param {String} sText + * @param {Number} nCorrectLevel + * @return {Number} type + */ + function _getTypeNumber (sText, nCorrectLevel) { + var nType = 1 + var length = _getUTF8Length(sText) + + for (var i = 0, len = QRCodeLimitLength.length; i <= len; i++) { + var nLimit = 0 + + switch (nCorrectLevel) { + case QRErrorCorrectLevel.L: + nLimit = QRCodeLimitLength[i][0] + break + case QRErrorCorrectLevel.M: + nLimit = QRCodeLimitLength[i][1] + break + case QRErrorCorrectLevel.Q: + nLimit = QRCodeLimitLength[i][2] + break + case QRErrorCorrectLevel.H: + nLimit = QRCodeLimitLength[i][3] + break + } + + if (length <= nLimit) { + break + } else { + nType++ + } + } + + if (nType > QRCodeLimitLength.length) { + throw new Error('Too long data') + } + + return nType + } + + function _getUTF8Length (sText) { + var replacedText = encodeURI(sText) + .toString() + .replace(/\%[0-9a-fA-F]{2}/g, 'a') + return replacedText.length + (replacedText.length != sText ? 3 : 0) + } + + /** + * @class QRCode + * @constructor + * @example + * new QRCode(document.getElementById("test"), "http://jindo.dev.naver.com/collie"); + * + * @example + * var oQRCode = new QRCode("test", { + * text : "http://naver.com", + * width : 128, + * height : 128 + * }); + * + * oQRCode.clear(); // Clear the QRCode. + * oQRCode.makeCode("http://map.naver.com"); // Re-create the QRCode. + * + * @param {HTMLElement|String} el target element or 'id' attribute of element. + * @param {Object|String} vOption + * @param {String} vOption.text QRCode link data + * @param {Number} [vOption.width=256] + * @param {Number} [vOption.height=256] + * @param {String} [vOption.colorDark="#000000"] + * @param {String} [vOption.colorLight="#ffffff"] + * @param {QRCode.CorrectLevel} [vOption.correctLevel=QRCode.CorrectLevel.H] [L|M|Q|H] + */ + QRCode = function (el, vOption) { + this._htOption = { + width: 256, + height: 256, + typeNumber: 4, + colorDark: '#000000', + colorLight: '#ffffff', + correctLevel: QRErrorCorrectLevel.H + } + + if (typeof vOption === 'string') { + vOption = { + text: vOption + } + } + + // Overwrites options + if (vOption) { + for (var i in vOption) { + this._htOption[i] = vOption[i] + } + } + + if (typeof el === 'string') { + el = document.getElementById(el) + } + + if (this._htOption.useSVG) { + Drawing = svgDrawer + } + + this._android = _getAndroid() + this._el = el + this._oQRCode = null + this._oDrawing = new Drawing(this._el, this._htOption) + + if (this._htOption.text) { + this.makeCode(this._htOption.text) + } + } + + /** + * Make the QRCode + * + * @param {String} sText link data + */ + QRCode.prototype.makeCode = function (sText) { + this._oQRCode = new QRCodeModel( + _getTypeNumber(sText, this._htOption.correctLevel), + this._htOption.correctLevel + ) + this._oQRCode.addData(sText) + this._oQRCode.make() + this._el.title = sText + this._oDrawing.draw(this._oQRCode) + this.makeImage() + } + + /** + * Make the Image from Canvas element + * - It occurs automatically + * - Android below 3 doesn't support Data-URI spec. + * + * @private + */ + QRCode.prototype.makeImage = function () { + if ( + typeof this._oDrawing.makeImage === 'function' && + (!this._android || this._android >= 3) + ) { + this._oDrawing.makeImage() + } + } + + /** + * Clear the QRCode + */ + QRCode.prototype.clear = function () { + this._oDrawing.clear() + } + + /** + * @name QRCode.CorrectLevel + */ + QRCode.CorrectLevel = QRErrorCorrectLevel +})() diff --git a/testing/web-platform/tests/tools/wave/www/lib/query-parser.js b/testing/web-platform/tests/tools/wave/www/lib/query-parser.js new file mode 100644 index 0000000000..c8ab8333d2 --- /dev/null +++ b/testing/web-platform/tests/tools/wave/www/lib/query-parser.js @@ -0,0 +1,12 @@ +var QueryParser = {}; + +QueryParser.parseQuery = function () { + var queryParameters = {}; + var keysAndValues = location.search.replace("?", "").split("&"); + for (var i = 0; i < keysAndValues.length; i++) { + var key = keysAndValues[i].split("=")[0]; + var value = keysAndValues[i].split("=")[1]; + queryParameters[key] = value; + } + return queryParameters; +}; diff --git a/testing/web-platform/tests/tools/wave/www/lib/screen-console.js b/testing/web-platform/tests/tools/wave/www/lib/screen-console.js new file mode 100644 index 0000000000..0e13b963a6 --- /dev/null +++ b/testing/web-platform/tests/tools/wave/www/lib/screen-console.js @@ -0,0 +1,16 @@ +function ScreenConsole(element) { + this._element = element; +} + +ScreenConsole.prototype.log = function () { + var text = ""; + for (var i = 0; i < arguments.length; i++) { + text += arguments[i] + " "; + } + console.log(text); + this._element.innerText += text + "\n"; +}; + +ScreenConsole.prototype.clear = function () { + this._element.innerText = ""; +}; diff --git a/testing/web-platform/tests/tools/wave/www/lib/ui.js b/testing/web-platform/tests/tools/wave/www/lib/ui.js new file mode 100644 index 0000000000..4abbece985 --- /dev/null +++ b/testing/web-platform/tests/tools/wave/www/lib/ui.js @@ -0,0 +1,100 @@ +const UI = { + createElement: config => { + if (!config) return; + const elementType = config.element || "div"; + const element = document.createElement(elementType); + + Object.keys(config).forEach(property => { + const value = config[property]; + switch (property.toLowerCase()) { + case "id": + case "src": + case "style": + case "placeholder": + case "title": + case "accept": + element.setAttribute(property, value); + return; + case "classname": + element.setAttribute("class", value); + return; + case "colspan": + element.setAttribute("colspan", value); + return; + case "text": + element.innerText = value; + return; + case "value": + element.value = value; + return; + case "html": + element.innerHTML = value; + return; + case "onclick": + element.onclick = value.bind(element); + return; + case "onchange": + element.onchange = value.bind(element); + return; + case "onkeydown": + element.onkeydown = value.bind(element); + return; + case "onkeyup": + element.onkeyup = value.bind(element); + return; + case "type": + if (elementType === "input") element.setAttribute("type", value); + return; + case "children": + if (value instanceof Array) { + value.forEach(child => { + const childElement = + child instanceof Element ? child : UI.createElement(child); + if (!childElement) return; + element.appendChild(childElement); + }); + } else { + const child = value; + const childElement = + child instanceof Element ? child : UI.createElement(child); + if (!childElement) return; + element.appendChild(childElement); + element.appendChild(childElement); + } + return; + case "disabled": + if (value) element.setAttribute("disabled", true); + return; + case "checked": + if (value) element.setAttribute("checked", true); + return; + case "indeterminate": + element.indeterminate = value; + return; + } + }); + return element; + }, + getElement: id => { + return document.getElementById(id); + }, + getRoot: () => { + return document.getElementsByTagName("body")[0]; + }, + scrollPositions: {}, + saveScrollPosition: elementId => { + let scrollElement = UI.getElement(elementId); + if (!scrollElement) return; + UI.scrollPositions[elementId] = { + scrollLeft: scrollElement.scrollLeft, + scrollRight: scrollElement.scrollRight + }; + }, + loadScrollPosition: elementId => { + let scrollElement = UI.getElement(elementId); + if (!scrollElement) return; + if (!UI.scrollPositions[elementId]) return; + scrollElement.scrollLeft = UI.scrollPositions[elementId].scrollLeft; + scrollElement.scrollRight = UI.scrollPositions[elementId].scrollRight; + } +}; diff --git a/testing/web-platform/tests/tools/wave/www/lib/utils.js b/testing/web-platform/tests/tools/wave/www/lib/utils.js new file mode 100644 index 0000000000..d84a2cb69c --- /dev/null +++ b/testing/web-platform/tests/tools/wave/www/lib/utils.js @@ -0,0 +1,57 @@ +const utils = { + parseQuery: queryString => { + if (queryString.indexOf("?") === -1) return {}; + queryString = queryString.split("?")[1]; + const query = {}; + for (let part of queryString.split("&")) { + const keyValue = part.split("="); + query[keyValue[0]] = keyValue[1] ? keyValue[1] : null; + } + return query; + }, + percent: (count, total) => { + const percent = Math.floor((count / total) * 10000) / 100; + if (!percent) { + return 0; + } + return percent; + }, + saveBlobAsFile: (blob, filename) => { + const url = URL.createObjectURL(blob); + const a = document.createElement("a"); + a.style.display = "none"; + document.body.appendChild(a); + a.href = url; + a.download = filename; + a.click(); + document.body.removeChild(a); + }, + millisToTimeString(totalMilliseconds) { + let milliseconds = (totalMilliseconds % 1000) + ""; + milliseconds = milliseconds.padStart(3, "0"); + let seconds = (Math.floor(totalMilliseconds / 1000) % 60) + ""; + seconds = seconds.padStart(2, "0"); + let minutes = (Math.floor(totalMilliseconds / 60000) % 60) + ""; + minutes = minutes.padStart(2, "0"); + let hours = Math.floor(totalMilliseconds / 3600000) + ""; + hours = hours.padStart(2, "0"); + return `${hours}:${minutes}:${seconds}`; + }, + getBrowserIcon(browser) { + switch (browser.toLowerCase()) { + case "firefox": + return "fab fa-firefox"; + case "edge": + return "fab fa-edge"; + case "chrome": + case "chromium": + return "fab fa-chrome"; + case "safari": + case "webkit": + return "fab fa-safari"; + } + }, + copyObject(object) { + return JSON.parse(JSON.stringify(object)); + } +}; diff --git a/testing/web-platform/tests/tools/wave/www/lib/wave-service.js b/testing/web-platform/tests/tools/wave/www/lib/wave-service.js new file mode 100644 index 0000000000..f7a60e153d --- /dev/null +++ b/testing/web-platform/tests/tools/wave/www/lib/wave-service.js @@ -0,0 +1,866 @@ +function sendRequest(method, uri, headers, data, onSuccess, onError) { + var xhr = new XMLHttpRequest(); + xhr.onload = function () { + if (xhr.status === 200) { + onSuccess(xhr.response); + } else { + if (onError) onError(xhr.status, xhr.response); + } + }; + xhr.onerror = function () { + if (onError) onError(); + }; + xhr.open(method, WaveService.uriPrefix + uri, true); + for (var header in headers) { + xhr.setRequestHeader(header, headers[header]); + } + xhr.send(data); + return xhr; +} + +var WEB_ROOT = "{{WEB_ROOT}}"; +var HTTP_PORT = "{{HTTP_PORT}}"; +var HTTPS_PORT = "{{HTTPS_PORT}}"; +var OPEN = "open"; +var CLOSED = "closed"; + +var WaveService = { + uriPrefix: WEB_ROOT, + socket: { + state: CLOSED, + onMessage: function () {}, + onOpen: function () {}, + onClose: function () {}, + send: function () {}, + close: function () {}, + onStateChange: function () {}, + }, + // SESSIONS API + createSession: function (configuration, onSuccess, onError) { + var data = JSON.stringify({ + tests: configuration.tests, + types: configuration.types, + timeouts: configuration.timeouts, + reference_tokens: configuration.referenceTokens, + expiration_date: configuration.expirationDate, + labels: configuration.labels, + }); + sendRequest( + "POST", + "api/sessions", + { "Content-Type": "application/json" }, + data, + function (response) { + var jsonObject = JSON.parse(response); + onSuccess(jsonObject.token); + }, + onError + ); + }, + readSession: function (token, onSuccess, onError) { + sendRequest( + "GET", + "api/sessions/" + token, + null, + null, + function (response) { + var jsonObject = JSON.parse(response); + onSuccess({ + token: jsonObject.token, + tests: jsonObject.tests, + types: jsonObject.types, + userAgent: jsonObject.user_agent, + labels: jsonObject.labels, + timeouts: jsonObject.timeouts, + browser: jsonObject.browser, + isPublic: jsonObject.is_public, + referenceTokens: jsonObject.reference_tokens, + }); + }, + onError + ); + }, + readMultipleSessions: function (tokens, onSuccess, onError) { + var requestsLeft = tokens.length; + if (requestsLeft === 0) onSuccess([]); + var configurations = []; + for (var i = 0; i < tokens.length; i++) { + var token = tokens[i]; + WaveService.readSession( + token, + function (configuration) { + requestsLeft--; + configurations.push(configuration); + if (requestsLeft === 0) onSuccess(configurations); + }, + function (status) { + if (status === 404) requestsLeft--; + if (status !== 404 && onError) onError(); + if (requestsLeft === 0) onSuccess(configurations); + } + ); + } + }, + readSessionStatus: function (token, onSuccess, onError) { + sendRequest( + "GET", + "api/sessions/" + token + "/status", + null, + null, + function (response) { + var jsonObject = JSON.parse(response); + var dateStarted = null; + if (jsonObject.date_started) { + dateStarted = new Date(jsonObject.date_started); + } + var dateFinished = null; + if (jsonObject.date_finished) { + dateFinished = new Date(jsonObject.date_finished); + } + var expirationDate = null; + if (jsonObject.expiration_date) { + expirationDate = new Date(jsonObject.expiration_date); + } + onSuccess({ + token: jsonObject.token, + dateStarted: dateStarted, + dateFinished: dateFinished, + testFilesCount: jsonObject.test_files_count, + testFilesCompleted: jsonObject.test_files_completed, + status: jsonObject.status, + expirationDate: expirationDate, + }); + }, + function () { + if (onError) onError(); + } + ); + }, + readMultipleSessionStatuses: function (tokens, onSuccess, onError) { + var requestsLeft = tokens.length; + if (requestsLeft === 0) onSuccess([]); + var statuses = []; + for (var i = 0; i < tokens.length; i++) { + var token = tokens[i]; + WaveService.readSessionStatus( + token, + function (status) { + requestsLeft--; + statuses.push(status); + if (requestsLeft === 0) onSuccess(statuses); + }, + function () { + requestsLeft--; + if (requestsLeft === 0) onSuccess(statuses); + } + ); + } + }, + readPublicSessions: function (onSuccess, onError) { + sendRequest( + "GET", + "api/sessions/public", + null, + null, + function (response) { + var jsonObject = JSON.parse(response); + onSuccess(jsonObject); + }, + onError + ); + }, + updateSession: function (token, configuration, onSuccess, onError) { + var data = JSON.stringify({ + tests: configuration.tests, + types: configuration.types, + timeouts: configuration.timeouts, + reference_tokens: configuration.referenceTokens, + expiration_date: configuration.expirationDate, + type: configuration.type, + }); + sendRequest( + "PUT", + "api/sessions/" + token, + { "Content-Type": "application/json" }, + data, + function () { + onSuccess(); + }, + onError + ); + }, + updateLabels: function (token, labels, onSuccess, onError) { + var data = JSON.stringify({ labels: labels }); + sendRequest( + "PUT", + "api/sessions/" + token + "/labels", + { "Content-Type": "application/json" }, + data, + function () { + if (onSuccess) onSuccess(); + }, + onError + ); + }, + findToken: function (fragment, onSuccess, onError) { + sendRequest( + "GET", + "api/sessions/" + fragment, + null, + null, + function (response) { + var jsonObject = JSON.parse(response); + onSuccess(jsonObject.token); + }, + onError + ); + }, + startSession: function (token, onSuccess, onError) { + sendRequest( + "POST", + "api/sessions/" + token + "/start", + null, + null, + function () { + onSuccess(); + }, + onError + ); + }, + pauseSession: function (token, onSuccess, onError) { + sendRequest( + "POST", + "api/sessions/" + token + "/pause", + null, + null, + function () { + onSuccess(); + }, + onError + ); + }, + stopSession: function (token, onSuccess, onError) { + sendRequest( + "POST", + "api/sessions/" + token + "/stop", + null, + null, + function () { + onSuccess(); + }, + onError + ); + }, + resumeSession: function (token, resumeToken, onSuccess, onError) { + var data = JSON.stringify({ resume_token: resumeToken }); + sendRequest( + "POST", + "api/sessions/" + token + "/resume", + { "Content-Type": "application/json" }, + data, + function () { + if (onSuccess) onSuccess(); + }, + function (response) { + if (onError) onError(response); + } + ); + }, + deleteSession: function (token, onSuccess, onError) { + sendRequest( + "DELETE", + "api/sessions/" + token, + null, + null, + function () { + onSuccess(); + }, + onError + ); + }, + + // TESTS API + readTestList: function (onSuccess, onError) { + sendRequest( + "GET", + "api/tests", + null, + null, + function (response) { + var jsonObject = JSON.parse(response); + onSuccess(jsonObject); + }, + onError + ); + }, + readNextTest: function (token, onSuccess, onError) { + sendRequest( + "GET", + "api/tests/" + token + "/next", + null, + null, + function (response) { + var jsonObject = JSON.parse(response); + onSuccess(jsonObject.next_test); + }, + onError + ); + }, + readLastCompletedTests: function (token, resultTypes, onSuccess, onError) { + var status = ""; + if (resultTypes) { + for (var i = 0; i < resultTypes.length; i++) { + var type = resultTypes[i]; + status += type + ","; + } + } + sendRequest( + "GET", + "api/tests/" + token + "/last_completed?status=" + status, + null, + null, + function (response) { + var tests = JSON.parse(response); + var parsedTests = []; + for (var status in tests) { + for (var i = 0; i < tests[status].length; i++) { + var path = tests[status][i]; + parsedTests.push({ path: path, status: status }); + } + } + onSuccess(parsedTests); + }, + onError + ); + }, + readMalfunctioningTests: function (token, onSuccess, onError) { + sendRequest( + "GET", + "api/tests/" + token + "/malfunctioning", + null, + null, + function (response) { + var tests = JSON.parse(response); + onSuccess(tests); + }, + function (response) { + var errorMessage = JSON.parse(response).error; + onError(errorMessage); + } + ); + }, + updateMalfunctioningTests: function ( + token, + malfunctioningTests, + onSuccess, + onError + ) { + var data = JSON.stringify(malfunctioningTests); + sendRequest( + "PUT", + "api/tests/" + token + "/malfunctioning", + { "Content-Type": "application/json" }, + data, + function () { + onSuccess(); + }, + function (response) { + var errorMessage = JSON.parse(response).error; + onError(errorMessage); + } + ); + }, + readAvailableApis: function (onSuccess, onError) { + sendRequest( + "GET", + "api/tests/apis", + null, + null, + function (response) { + var apis = JSON.parse(response); + onSuccess(apis); + }, + function (response) { + if (!onError) return; + var errorMessage = JSON.parse(response).error; + onError(errorMessage); + } + ); + }, + + // RESULTS API + createResult: function (token, result, onSuccess, onError) { + sendRequest( + "POST", + "api/results/" + token, + { "Content-Type": "application/json" }, + JSON.stringify(result), + function () { + onSuccess(); + }, + onError + ); + }, + readResults: function (token, onSuccess, onError) { + sendRequest( + "GET", + "api/results/" + token, + null, + null, + function (response) { + onSuccess(JSON.parse(response)); + }, + onError + ); + }, + readResultsCompact: function (token, onSuccess, onError) { + sendRequest( + "GET", + "api/results/" + token + "/compact", + null, + null, + function (response) { + var jsonObject = JSON.parse(response); + onSuccess(jsonObject); + }, + onError + ); + }, + readResultComparison: function (tokens, onSuccess, onError) { + var comparison = {}; + var fetchComplete = function (results) { + comparison.total = {}; + for (var i = 0; i < results.length; i++) { + var result = results[i]; + var token = result.token; + comparison[token] = {}; + for (var api in result) { + if (api === "token") continue; + comparison[token][api] = result[api].pass; + if (!comparison.total[api]) { + var total = 0; + for (var status in result[api]) { + total = total + result[api][status]; + } + comparison.total[api] = total; + } + } + } + onSuccess(comparison); + }; + var requestsLeft = tokens.length; + if (requestsLeft === 0) onSuccess([]); + var results = []; + for (var i = 0; i < tokens.length; i++) { + var token = tokens[i]; + (function (token) { + WaveService.readResultsCompact( + token, + function (result) { + requestsLeft--; + result.token = token; + results.push(result); + if (requestsLeft === 0) fetchComplete(results); + }, + function (responseStatus) { + if (responseStatus === 404) requestsLeft--; + if (status !== 404 && onError) onError(); + if (requestsLeft === 0) fetchComplete(results); + } + ); + })(token); + } + }, + downloadResults: function (token) { + location.href = "api/results/" + token + "/export"; + }, + downloadApiResult: function (token, api) { + location.href = "api/results/" + token + "/" + api + "/json"; + }, + downloadAllApiResults: function (token, api) { + location.href = "api/results/" + token + "/json"; + }, + downloadReport: function (token, api) { + location.href = "api/results/" + token + "/" + api + "/report"; + }, + importResults: function (data, onSuccess, onError) { + sendRequest( + "POST", + "api/results/import", + { "Content-Type": "application/octet-stream" }, + data, + function (response) { + var token = JSON.parse(response).token; + onSuccess(token); + }, + function (status, response) { + var errorMessage; + if (status === 500) { + errorMessage = "Internal server error."; + } else { + errorMessage = JSON.parse(response).error; + } + onError(errorMessage); + } + ); + }, + readReportUri: function (token, api, onSuccess, onError) { + sendRequest( + "GET", + "api/results/" + token + "/" + api + "/reporturl", + null, + null, + function (response) { + var jsonObject = JSON.parse(response); + onSuccess(jsonObject.uri); + }, + onError + ); + }, + downloadMultiReport: function (tokens, api) { + location.href = "api/results/" + api + "/report?tokens=" + tokens.join(","); + }, + readMultiReportUri: function (tokens, api, onSuccess, onError) { + sendRequest( + "GET", + "api/results/" + api + "/reporturl?tokens=" + tokens.join(","), + null, + null, + function (response) { + var jsonObject = JSON.parse(response); + onSuccess(jsonObject.uri); + }, + onError + ); + }, + downloadResultsOverview: function (token) { + location.href = "api/results/" + token + "/overview"; + }, + + // DEVICES API + _device_token: null, + _deviceEventListeners: {}, + _deviceEventNumbers: {}, + registerDevice: function (onSuccess, onError) { + sendRequest( + "POST", + "api/devices", + null, + null, + function (response) { + var data = JSON.parse(response); + WaveService._device_token = data.token; + onSuccess(data.token); + }, + onError + ); + }, + readDevice: function (token, onSuccess, onError) { + sendRequest( + "GET", + "api/devices/" + token, + null, + null, + function (response) { + if (!onSuccess) return; + var data = JSON.parse(response); + onSuccess(data); + }, + function (error) { + if (!onError) return; + onError(error); + } + ); + }, + DEVICE_ADDED_EVENT: "device_added", + DEVICE_REMOVED_EVENT: "device_removed", + START_SESSION: "start_session", + addDeviceEventListener: function (token, callback) { + var listeners = WaveService._deviceEventListeners; + if (!listeners[token]) listeners[token] = []; + listeners[token].push(callback); + WaveService._deviceEventListeners = listeners; + WaveService.listenDeviceEvents(token); + }, + removeDeviceEventListener: function (callback) { + var listeners = WaveService._deviceEventListeners; + for (var token of Object.keys(listeners)) { + var index = listeners[token].indexOf(callback); + if (index === -1) continue; + listeners[token].splice(index, 1); + break; + } + WaveService._deviceEventListeners = listeners; + }, + listenDeviceEvents: function (token) { + var listeners = WaveService._deviceEventListeners; + if (!listeners[token] || listeners.length === 0) return; + var url = "api/devices/" + token + "/events"; + var lastEventNumber = WaveService._deviceEventNumbers[token]; + if (lastEventNumber) { + url += "?last_active=" + lastEventNumber; + } + WaveService.listenHttpPolling( + url, + function (response) { + if (!response) { + WaveService.listenDeviceEvents(token); + return; + } + for (var listener of listeners[token]) { + listener(response); + } + WaveService._deviceEventNumbers[token] = lastEventNumber; + WaveService.listenDeviceEvents(token); + }, + function () { + setTimeout(function () { + WaveService.listenDeviceEvents(); + }, 1000); + } + ); + }, + sendDeviceEvent: function (device_token, event, onSuccess, onError) { + var data = JSON.stringify({ + type: event.type, + data: event.data, + }); + sendRequest( + "POST", + "api/devices/" + device_token + "/events", + { "Content-Type": "application/json" }, + data, + onSuccess, + onError + ); + }, + addGlobalDeviceEventListener: function (callback) { + WaveService._globalDeviceEventListeners.push(callback); + WaveService.listenGlobalDeviceEvents(); + }, + removeGlobalDeviceEventListener: function (callback) { + var index = WaveService._globalDeviceEventListeners.indexOf(callback); + WaveService._globalDeviceEventListeners.splice(index, 1); + }, + listenGlobalDeviceEvents: function () { + var listeners = WaveService._globalDeviceEventListeners; + if (listeners.length === 0) return; + var query = ""; + if (WaveService._device_token) { + query = "?device_token=" + WaveService._device_token; + } + WaveService.listenHttpPolling( + "api/devices/events" + query, + function (response) { + if (!response) { + WaveService.listenGlobalDeviceEvents(); + return; + } + for (var listener of listeners) { + listener(response); + } + WaveService.listenGlobalDeviceEvents(); + }, + function () { + setTimeout(function () { + WaveService.listenGlobalDeviceEvents(); + }, 1000); + } + ); + }, + sendGlobalDeviceEvent: function (event, onSuccess, onError) { + var data = JSON.stringify({ + type: event.type, + data: event.data, + }); + sendRequest( + "POST", + "api/devices/events", + { "Content-Type": "application/json" }, + data, + onSuccess, + onError + ); + }, + + // GENERAL API + readStatus: function (onSuccess, onError) { + sendRequest( + "GET", + "api/status", + null, + null, + function (response) { + var data = JSON.parse(response); + var configuration = { + readSessionsEnabled: data.read_sessions_enabled, + importResultsEnabled: data.import_results_enabled, + reportsEnabled: data.reports_enabled, + versionString: data.version_string, + testTypeSelectionEnabled: data.test_type_selection_enabled, + testFileSelectionEnabled: data.test_file_selection_enabled + }; + onSuccess(configuration); + }, + onError + ); + }, + + // UTILITY + addRecentSession: function (token) { + if (!token) return; + var state = WaveService.getState(); + if (!state.recent_sessions) state.recent_sessions = []; + if (state.recent_sessions.indexOf(token) !== -1) return; + state.recent_sessions.unshift(token); + WaveService.setState(state); + }, + addRecentSessions: function (tokens) { + for (var i = 0; i < tokens.length; i++) { + var token = tokens[i]; + WaveService.addRecentSession(token); + } + }, + getPinnedSessions: function () { + var state = WaveService.getState(); + if (!state || !state.pinned_sessions) return []; + return state.pinned_sessions; + }, + addPinnedSession: function (token) { + if (!token) return; + var state = WaveService.getState(); + if (!state.pinned_sessions) state.pinned_sessions = []; + if (state.pinned_sessions.indexOf(token) !== -1) return; + state.pinned_sessions.unshift(token); + WaveService.setState(state); + }, + getRecentSessions: function () { + var state = WaveService.getState(); + if (!state || !state.recent_sessions) return []; + return state.recent_sessions; + }, + setRecentSessions: function (sessionTokens) { + var state = WaveService.getState(); + state.recent_sessions = sessionTokens; + WaveService.setState(state); + }, + removePinnedSession: function (token) { + if (!token) return; + var state = WaveService.getState(); + if (!state.pinned_sessions) return; + var index = state.pinned_sessions.indexOf(token); + if (index === -1) return; + state.pinned_sessions.splice(index, 1); + WaveService.setState(state); + }, + removeRecentSession: function (token) { + var state = WaveService.getState(); + if (!state.recent_sessions) return; + var index = state.recent_sessions.indexOf(token); + if (index === -1) return; + state.recent_sessions.splice(index, 1); + WaveService.setState(state); + }, + getState: function () { + if (!window.localStorage) return null; + var storage = window.localStorage; + var state = JSON.parse(storage.getItem("wave")); + if (!state) return {}; + return state; + }, + setState: function (state) { + if (!window.localStorage) return null; + var storage = window.localStorage; + storage.setItem("wave", JSON.stringify(state)); + }, + _globalDeviceEventListeners: [], + _sessionEventListeners: {}, + _sessionEventNumbers: {}, + listenHttpPolling: function (url, onSuccess, onError) { + var uniqueId = new Date().getTime(); + if (url.indexOf("?") === -1) { + url = url + "?id=" + uniqueId; + } else { + url = url + "&id=" + uniqueId; + } + sendRequest( + "GET", + url, + null, + null, + function (response) { + if (!response) { + onSuccess(null); + return; + } + onSuccess(JSON.parse(response)); + }, + onError + ); + }, + addSessionEventListener: function (token, callback) { + var listeners = WaveService._sessionEventListeners; + if (!listeners[token]) listeners[token] = []; + if (listeners[token].indexOf(callback) >= 0) return; + listeners[token].push(callback); + WaveService._sessionEventListeners = listeners; + WaveService.listenSessionEvents(token); + }, + removeSessionEventListener: function (callback) { + var listeners = WaveService._sessionEventListeners; + for (var token of Object.keys(listeners)) { + var index = listeners[token].indexOf(callback); + if (index === -1) continue; + listeners[token].splice(index, 1); + break; + } + WaveService._sessionEventListeners = listeners; + }, + listenSessionEvents: function (token) { + var listeners = WaveService._sessionEventListeners; + if (!listeners[token] || listeners.length === 0) return; + var url = "api/sessions/" + token + "/events"; + var lastEventNumber = WaveService._sessionEventNumbers[token]; + if (lastEventNumber) { + url += "?last_event=" + lastEventNumber; + } + WaveService.listenHttpPolling( + url, + function (response) { + if (!response) { + WaveService.listenSessionEvents(token); + return; + } + var lastEventNumber = 0; + for (var listener of listeners[token]) { + for (var event of response) { + if (event.number > lastEventNumber) { + lastEventNumber = event.number; + } + listener(event); + } + } + WaveService._sessionEventNumbers[token] = lastEventNumber; + WaveService.listenSessionEvents(token); + }, + function () { + setTimeout(function () { + WaveService.listenSessionEvents(); + }, 1000); + } + ); + }, + openSession: function (token) { + location.href = "/results.html?token=" + token; + }, +}; + +if (!Object.keys) + Object.keys = function (o) { + if (o !== Object(o)) + throw new TypeError("Object.keys called on a non-object"); + var k = [], + p; + for (p in o) if (Object.prototype.hasOwnProperty.call(o, p)) k.push(p); + return k; + }; -- cgit v1.2.3