From baf9147305c6206b77eccd0873e02949ed76a16e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Mon, 28 Nov 2022 12:37:21 +0900 Subject: [PATCH 01/14] Add tests --- .../server/middleware-build-manifest/input.js | 1 + .../input.js | 1 + .../chunks/390-4d47e666b03015d5/input.js | 3546 ++++++++++ .../framework-5ab552f91d1ae590/input.js | 496 ++ .../chunks/main-0fdc0c4ebee9ebae/input.js | 5682 +++++++++++++++++ .../pages/_app-0c9a37e84b559226/input.js | 55 + .../pages/_error-c8b0663085900c58/input.js | 25 + .../pages/index-e1d69965f0f167c9/input.js | 96 + .../chunks/webpack-d8d0d5dfdfeffdbf/input.js | 177 + .../_buildManifest/input.js | 1 + .../_ssgManifest/input.js | 1 + 11 files changed, 10081 insertions(+) create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/43208/server/middleware-build-manifest/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/43208/server/middleware-react-loadable-manifest/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/43208/static/chunks/390-4d47e666b03015d5/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/43208/static/chunks/framework-5ab552f91d1ae590/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/43208/static/chunks/main-0fdc0c4ebee9ebae/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/43208/static/chunks/pages/_app-0c9a37e84b559226/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/43208/static/chunks/pages/_error-c8b0663085900c58/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/43208/static/chunks/pages/index-e1d69965f0f167c9/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/43208/static/chunks/webpack-d8d0d5dfdfeffdbf/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/43208/static/gRPIwLIWdw6kPkiwZ23uc/_buildManifest/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/43208/static/gRPIwLIWdw6kPkiwZ23uc/_ssgManifest/input.js diff --git a/crates/swc_ecma_minifier/tests/fixture/next/43208/server/middleware-build-manifest/input.js b/crates/swc_ecma_minifier/tests/fixture/next/43208/server/middleware-build-manifest/input.js new file mode 100644 index 000000000000..69a32571123c --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/next/43208/server/middleware-build-manifest/input.js @@ -0,0 +1 @@ +self.__BUILD_MANIFEST={"polyfillFiles":["static/chunks/polyfills-c67a75d1b6f99dc8.js"],"devFiles":[],"ampDevFiles":[],"lowPriorityFiles":["static/gRPIwLIWdw6kPkiwZ23uc/_buildManifest.js","static/gRPIwLIWdw6kPkiwZ23uc/_ssgManifest.js"],"rootMainFiles":[],"pages":{"/":["static/chunks/webpack-d8d0d5dfdfeffdbf.js","static/chunks/framework-5ab552f91d1ae590.js","static/chunks/main-0fdc0c4ebee9ebae.js","static/chunks/390-4d47e666b03015d5.js","static/css/1f408fb086109472.css","static/chunks/pages/index-e1d69965f0f167c9.js"],"/_app":["static/chunks/webpack-d8d0d5dfdfeffdbf.js","static/chunks/framework-5ab552f91d1ae590.js","static/chunks/main-0fdc0c4ebee9ebae.js","static/css/e642fefc6f19f6c3.css","static/chunks/pages/_app-0c9a37e84b559226.js"],"/_error":["static/chunks/webpack-d8d0d5dfdfeffdbf.js","static/chunks/framework-5ab552f91d1ae590.js","static/chunks/main-0fdc0c4ebee9ebae.js","static/chunks/pages/_error-c8b0663085900c58.js"]},"ampFirstPages":[]} \ No newline at end of file diff --git a/crates/swc_ecma_minifier/tests/fixture/next/43208/server/middleware-react-loadable-manifest/input.js b/crates/swc_ecma_minifier/tests/fixture/next/43208/server/middleware-react-loadable-manifest/input.js new file mode 100644 index 000000000000..7f1b4e589ecc --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/next/43208/server/middleware-react-loadable-manifest/input.js @@ -0,0 +1 @@ +self.__REACT_LOADABLE_MANIFEST={} \ No newline at end of file diff --git a/crates/swc_ecma_minifier/tests/fixture/next/43208/static/chunks/390-4d47e666b03015d5/input.js b/crates/swc_ecma_minifier/tests/fixture/next/43208/static/chunks/390-4d47e666b03015d5/input.js new file mode 100644 index 000000000000..fc89458efd43 --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/next/43208/static/chunks/390-4d47e666b03015d5/input.js @@ -0,0 +1,3546 @@ +(self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([[390],{ + +/***/ 9996: +/***/ (function(__unused_webpack_module, exports, __webpack_require__) { + +"use strict"; +function _typeof(obj) {if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {_typeof = function _typeof(obj) {return typeof obj;};} else {_typeof = function _typeof(obj) {return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;};}return _typeof(obj);} //= ======================================================================================= +// Globals +//= ======================================================================================= +var _require = __webpack_require__(1876),Buffer = _require.Buffer; +var vm = __webpack_require__(22); + +var Context = (__webpack_require__(2961)/* .Context */ ._); +var Long = __webpack_require__(3720); + +if (typeof window !== "undefined") window.Buffer = Buffer; +if (typeof self !== "undefined") self.Buffer = Buffer; // this is for webworker, and also is not an elseif to avoid window polyfills in webworker + +var PRIMITIVE_TYPES = { + UInt8: 1, + UInt16LE: 2, + UInt16BE: 2, + UInt32LE: 4, + UInt32BE: 4, + Int8: 1, + Int16LE: 2, + Int16BE: 2, + Int32LE: 4, + Int32BE: 4, + FloatLE: 4, + FloatBE: 4, + DoubleLE: 8, + DoubleBE: 8, + UInt64: 8, + Int64: 8 }; + + +var SPECIAL_TYPES = { + String: null, + Buffer: null, + Array: null, + Skip: null, + Choice: null, + Nest: null, + Bit: null, + Itf8: null, + Ltf8: null }; + + +var aliasRegistry = {}; +var FUNCTION_PREFIX = "___parser_"; + +var BIT_RANGE = []; +(function () { + var i; + for (i = 1; i <= 32; i++) { + BIT_RANGE.push(i); + } +})(); + +// Converts Parser's method names to internal type names +var NAME_MAP = {}; +Object.keys(PRIMITIVE_TYPES). +concat(Object.keys(SPECIAL_TYPES)). +forEach(function (type) { + NAME_MAP[type.toLowerCase()] = type; +}); + +//= ======================================================================================= +// class Parser +//= ======================================================================================= + +//---------------------------------------------------------------------------------------- +// constructor +//---------------------------------------------------------------------------------------- + +var Parser = function Parser() { + this.varName = ""; + this.type = ""; + this.options = {}; + this.next = null; + this.head = null; + this.compiled = null; + this.endian = "le"; + this.constructorFn = null; + this.alias = null; +}; + +//---------------------------------------------------------------------------------------- +// public methods +//---------------------------------------------------------------------------------------- + +Parser.start = function () { + return new Parser(); +}; + +Object.keys(PRIMITIVE_TYPES).forEach(function (type) { + Parser.prototype[type.toLowerCase()] = function (varName, options) { + return this.setNextParser(type.toLowerCase(), varName, options); + }; + + var typeWithoutEndian = type.replace(/BE|LE/, "").toLowerCase(); + if (!(typeWithoutEndian in Parser.prototype)) { + Parser.prototype[typeWithoutEndian] = function (varName, options) { + return this[typeWithoutEndian + this.endian](varName, options); + }; + } +}); + +BIT_RANGE.forEach(function (i) { + Parser.prototype["bit".concat(i.toString())] = function (varName, options) { + if (!options) { + options = {}; + } + options.length = i; + return this.setNextParser("bit", varName, options); + }; +}); + +Parser.prototype.namely = function (alias) { + aliasRegistry[alias] = this; + this.alias = alias; + return this; +}; + +Parser.prototype.skip = function (length, options) { + if (options && options.assert) { + throw new Error("assert option on skip is not allowed."); + } + + return this.setNextParser("skip", "", { length: length }); +}; + +Parser.prototype.string = function (varName, options) { + if (!options.zeroTerminated && !options.length && !options.greedy) { + throw new Error( + "Neither length, zeroTerminated, nor greedy is defined for string."); + + } + if ((options.zeroTerminated || options.length) && options.greedy) { + throw new Error( + "greedy is mutually exclusive with length and zeroTerminated for string."); + + } + if (options.stripNull && !(options.length || options.greedy)) { + throw new Error( + "Length or greedy must be defined if stripNull is defined."); + + } + options.encoding = options.encoding || "utf8"; + + return this.setNextParser("string", varName, options); +}; + +Parser.prototype.buffer = function (varName, options) { + if (!options.length && !options.readUntil) { + throw new Error("Length nor readUntil is defined in buffer parser"); + } + + return this.setNextParser("buffer", varName, options); +}; + +Parser.prototype.array = function (varName, options) { + if (!options.readUntil && !options.length && !options.lengthInBytes) { + throw new Error("Length option of array is not defined."); + } + if (!options.type) { + throw new Error("Type option of array is not defined."); + } + if ( + typeof options.type === "string" && + !aliasRegistry[options.type] && + Object.keys(PRIMITIVE_TYPES).indexOf(NAME_MAP[options.type]) < 0) + { + throw new Error("Specified primitive type \"".concat( + options.type, "\" is not supported.")); + + } + + return this.setNextParser("array", varName, options); +}; + +Parser.prototype.choice = function (varName, options) { + if (arguments.length === 1 && _typeof(varName) === "object") { + options = varName; + varName = null; + } + + if (!options.tag) { + throw new Error("Tag option of array is not defined."); + } + if (!options.choices) { + throw new Error("Choices option of array is not defined."); + } + + Object.keys(options.choices).forEach(function (key) { + // if (isNaN(parseInt(key, 10))) { + // throw new Error("Key of choices must be a number."); + // } + if (!options.choices[key]) { + throw new Error("Choice Case ".concat(key, " of ").concat(varName, " is not valid.")); + } + + if ( + typeof options.choices[key] === "string" && + !aliasRegistry[options.choices[key]] && + Object.keys(PRIMITIVE_TYPES).indexOf(NAME_MAP[options.choices[key]]) < 0) + { + throw new Error("Specified primitive type \"".concat( + options.choices[key], "\" is not supported.")); + + } + }, this); + + return this.setNextParser("choice", varName, options); +}; + +Parser.prototype.nest = function (varName, options) { + if (arguments.length === 1 && _typeof(varName) === "object") { + options = varName; + varName = null; + } + + if (!options.type) { + throw new Error("Type option of nest is not defined."); + } + if (!(options.type instanceof Parser) && !aliasRegistry[options.type]) { + throw new Error("Type option of nest must be a Parser object."); + } + if (!(options.type instanceof Parser) && !varName) { + throw new Error( + "options.type must be a object if variable name is omitted."); + + } + + return this.setNextParser("nest", varName, options); +}; + +Parser.prototype.endianess = function (endianess) { + switch (endianess.toLowerCase()) { + case "little": + this.endian = "le"; + break; + case "big": + this.endian = "be"; + break; + default: + throw new Error("Invalid endianess: ".concat(endianess));} + + + return this; +}; + +Parser.prototype.create = function (constructorFn) { + if (!(constructorFn instanceof Function)) { + throw new Error("Constructor must be a Function object."); + } + + this.constructorFn = constructorFn; + + return this; +}; + +Parser.prototype.getCode = function () { + var ctx = new Context(); + + ctx.pushCode("if (!Buffer.isBuffer(buffer)) {"); + ctx.generateError('"argument buffer is not a Buffer object"'); + ctx.pushCode("}"); + + if (!this.alias) { + this.addRawCode(ctx); + } else { + this.addAliasedCode(ctx); + } + + if (this.alias) { + ctx.pushCode("return {0}(0)", FUNCTION_PREFIX + this.alias); + } else { + ctx.pushCode("return { offset: offset, result: vars };"); + } + + return ctx.code; +}; + +Parser.prototype.addRawCode = function (ctx) { + ctx.pushCode("var offset = 0;"); + + if (this.constructorFn) { + ctx.pushCode("var vars = new constructorFn();"); + } else { + ctx.pushCode("var vars = {};"); + } + + this.generate(ctx); + + this.resolveReferences(ctx); + + ctx.pushCode("return { offset: offset, result: vars };"); +}; + +Parser.prototype.addAliasedCode = function (ctx) { + ctx.pushCode("function {0}(offset) {", FUNCTION_PREFIX + this.alias); + + if (this.constructorFn) { + ctx.pushCode("var vars = new constructorFn();"); + } else { + ctx.pushCode("var vars = {};"); + } + + this.generate(ctx); + + ctx.markResolved(this.alias); + this.resolveReferences(ctx); + + ctx.pushCode("return { offset: offset, result: vars };"); + ctx.pushCode("}"); + + return ctx; +}; + +Parser.prototype.resolveReferences = function (ctx) { + var references = ctx.getUnresolvedReferences(); + ctx.markRequested(references); + references.forEach(function (alias) { + var parser = aliasRegistry[alias]; + parser.addAliasedCode(ctx); + }); +}; + +Parser.prototype.compile = function () { + var src = "(function(buffer, constructorFn, Long) { ".concat(this.getCode(), " })"); + this.compiled = vm.runInThisContext(src); +}; + +Parser.prototype.sizeOf = function () { + var size = NaN; + + if (Object.keys(PRIMITIVE_TYPES).indexOf(this.type) >= 0) { + size = PRIMITIVE_TYPES[this.type]; + + // if this is a fixed length string + } else if ( + this.type === "String" && + typeof this.options.length === "number") + { + size = this.options.length; + + // if this is a fixed length buffer + } else if ( + this.type === "Buffer" && + typeof this.options.length === "number") + { + size = this.options.length; + + // if this is a fixed length array + } else if (this.type === "Array" && typeof this.options.length === "number") { + var elementSize = NaN; + if (typeof this.options.type === "string") { + elementSize = PRIMITIVE_TYPES[NAME_MAP[this.options.type]]; + } else if (this.options.type instanceof Parser) { + elementSize = this.options.type.sizeOf(); + } + size = this.options.length * elementSize; + + // if this a skip + } else if (this.type === "Skip") { + size = this.options.length; + + // if this is a nested parser + } else if (this.type === "Nest") { + size = this.options.type.sizeOf(); + } else if (!this.type) { + size = 0; + } + + if (this.next) { + size += this.next.sizeOf(); + } + + return size; +}; + +// Follow the parser chain till the root and start parsing from there +Parser.prototype.parse = function (buffer) { + if (!this.compiled) { + this.compile(); + } + + return this.compiled(buffer, this.constructorFn, Long); +}; + +//---------------------------------------------------------------------------------------- +// private methods +//---------------------------------------------------------------------------------------- + +Parser.prototype.setNextParser = function (type, varName, options) { + var parser = new Parser(); + + parser.type = NAME_MAP[type]; + parser.varName = varName; + parser.options = options || parser.options; + parser.endian = this.endian; + + if (this.head) { + this.head.next = parser; + } else { + this.next = parser; + } + this.head = parser; + + return this; +}; + +// Call code generator for this parser +Parser.prototype.generate = function (ctx) { + if (this.type) { + this["generate".concat(this.type)](ctx); + this.generateAssert(ctx); + } + + var varName = ctx.generateVariable(this.varName); + if (this.options.formatter) { + this.generateFormatter(ctx, varName, this.options.formatter); + } + + return this.generateNext(ctx); +}; + +Parser.prototype.generateAssert = function (ctx) { + if (!this.options.assert) { + return; + } + + var varName = ctx.generateVariable(this.varName); + + switch (_typeof(this.options.assert)) { + case "function": + ctx.pushCode( + "if (!({0}).call(vars, {1})) {", + this.options.assert, + varName); + + break; + case "number": + ctx.pushCode("if ({0} !== {1}) {", this.options.assert, varName); + break; + case "string": + ctx.pushCode('if ("{0}" !== {1}) {', this.options.assert, varName); + break; + default: + throw new Error( + "Assert option supports only strings, numbers and assert functions.");} + + + ctx.generateError('"Assert error: {0} is " + {0}', varName); + ctx.pushCode("}"); +}; + +// Recursively call code generators and append results +Parser.prototype.generateNext = function (ctx) { + if (this.next) { + ctx = this.next.generate(ctx); + } + + return ctx; +}; + +Object.keys(PRIMITIVE_TYPES).forEach(function (type) { + Parser.prototype["generate".concat(type)] = function (ctx) { + if (type === "UInt64") { + ctx.pushCode( + "{0} = Long.fromBytes(buffer.slice(offset,offset+8), true, this.endian === 'le').toNumber();", + ctx.generateVariable(this.varName), + type); + + } else if (type === "Int64") { + ctx.pushCode( + "{0} = Long.fromBytes(buffer.slice(offset,offset+8), false, this.endian === 'le').toNumber();", + ctx.generateVariable(this.varName), + type); + + } else { + ctx.pushCode( + "{0} = buffer.read{1}(offset);", + ctx.generateVariable(this.varName), + type); + + } + ctx.pushCode("offset += {0};", PRIMITIVE_TYPES[type]); + }; +}); + +Parser.prototype.generateBit = function (ctx) { + // TODO find better method to handle nested bit fields + var parser = JSON.parse(JSON.stringify(this)); + parser.varName = ctx.generateVariable(parser.varName); + ctx.bitFields.push(parser); + + if ( + !this.next || + this.next && ["Bit", "Nest"].indexOf(this.next.type) < 0) + { + var sum = 0; + ctx.bitFields.forEach(function (p) { + sum += p.options.length; + }); + + var val = ctx.generateTmpVariable(); + + if (sum <= 8) { + ctx.pushCode("var {0} = buffer.readUInt8(offset);", val); + sum = 8; + } else if (sum <= 16) { + ctx.pushCode("var {0} = buffer.readUInt16BE(offset);", val); + sum = 16; + } else if (sum <= 24) { + var val1 = ctx.generateTmpVariable(); + var val2 = ctx.generateTmpVariable(); + ctx.pushCode("var {0} = buffer.readUInt16BE(offset);", val1); + ctx.pushCode("var {0} = buffer.readUInt8(offset + 2);", val2); + ctx.pushCode("var {2} = ({0} << 8) | {1};", val1, val2, val); + sum = 24; + } else if (sum <= 32) { + ctx.pushCode("var {0} = buffer.readUInt32BE(offset);", val); + sum = 32; + } else { + throw new Error( + "Currently, bit field sequence longer than 4-bytes is not supported."); + + } + ctx.pushCode("offset += {0};", sum / 8); + + var bitOffset = 0; + var isBigEndian = this.endian === "be"; + ctx.bitFields.forEach(function (p) { + ctx.pushCode( + "{0} = {1} >> {2} & {3};", + p.varName, + val, + isBigEndian ? sum - bitOffset - p.options.length : bitOffset, + (1 << p.options.length) - 1); + + bitOffset += p.options.length; + }); + + ctx.bitFields = []; + } +}; + +Parser.prototype.generateSkip = function (ctx) { + var length = ctx.generateOption(this.options.length); + ctx.pushCode("offset += {0};", length); +}; + +Parser.prototype.generateString = function (ctx) { + var name = ctx.generateVariable(this.varName); + var start = ctx.generateTmpVariable(); + + if (this.options.length && this.options.zeroTerminated) { + ctx.pushCode("var {0} = offset;", start); + ctx.pushCode( + "while(buffer.readUInt8(offset++) !== 0 && offset - {0} < {1});", + start, + this.options.length); + + ctx.pushCode( + "{0} = buffer.toString('{1}', {2}, offset - {2} < {3} ? offset - 1 : offset);", + name, + this.options.encoding, + start, + this.options.length); + + } else if (this.options.length) { + ctx.pushCode( + "{0} = buffer.toString('{1}', offset, offset + {2});", + name, + this.options.encoding, + ctx.generateOption(this.options.length)); + + ctx.pushCode("offset += {0};", ctx.generateOption(this.options.length)); + } else if (this.options.zeroTerminated) { + ctx.pushCode("var {0} = offset;", start); + ctx.pushCode("while(buffer.readUInt8(offset++) !== 0);"); + ctx.pushCode( + "{0} = buffer.toString('{1}', {2}, offset - 1);", + name, + this.options.encoding, + start); + + } else if (this.options.greedy) { + ctx.pushCode("var {0} = offset;", start); + ctx.pushCode("while(buffer.length > offset++);"); + ctx.pushCode( + "{0} = buffer.toString('{1}', {2}, offset);", + name, + this.options.encoding, + start); + + } + if (this.options.stripNull) { + ctx.pushCode("{0} = {0}.replace(/\\x00+$/g, '')", name); + } +}; + +Parser.prototype.generateBuffer = function (ctx) { + if (this.options.readUntil === "eof") { + ctx.pushCode( + "{0} = buffer.slice(offset);", + ctx.generateVariable(this.varName)); + + } else { + ctx.pushCode( + "{0} = buffer.slice(offset, offset + {1});", + ctx.generateVariable(this.varName), + ctx.generateOption(this.options.length)); + + ctx.pushCode("offset += {0};", ctx.generateOption(this.options.length)); + } + + if (this.options.clone) { + ctx.pushCode("{0} = Buffer.from({0});", ctx.generateVariable(this.varName)); + } +}; + +Parser.prototype.generateArray = function (ctx) { + var length = ctx.generateOption(this.options.length); + var lengthInBytes = ctx.generateOption(this.options.lengthInBytes); + var type = this.options.type; + var counter = ctx.generateTmpVariable(); + var lhs = ctx.generateVariable(this.varName); + var item = ctx.generateTmpVariable(); + var key = this.options.key; + var isHash = typeof key === "string"; + + if (isHash) { + ctx.pushCode("{0} = {};", lhs); + } else { + ctx.pushCode("{0} = [];", lhs); + } + if (typeof this.options.readUntil === "function") { + ctx.pushCode("do {"); + } else if (this.options.readUntil === "eof") { + ctx.pushCode("for (var {0} = 0; offset < buffer.length; {0}++) {", counter); + } else if (lengthInBytes !== undefined) { + ctx.pushCode( + "for (var {0} = offset; offset - {0} < {1}; ) {", + counter, + lengthInBytes); + + } else { + ctx.pushCode("for (var {0} = 0; {0} < {1}; {0}++) {", counter, length); + } + + if (typeof type === "string") { + if (!aliasRegistry[type]) { + ctx.pushCode("var {0} = buffer.read{1}(offset);", item, NAME_MAP[type]); + ctx.pushCode("offset += {0};", PRIMITIVE_TYPES[NAME_MAP[type]]); + } else { + var tempVar = ctx.generateTmpVariable(); + ctx.pushCode("var {0} = {1}(offset);", tempVar, FUNCTION_PREFIX + type); + ctx.pushCode("var {0} = {1}.result; offset = {1}.offset;", item, tempVar); + if (type !== this.alias) ctx.addReference(type); + } + } else if (type instanceof Parser) { + ctx.pushCode("var {0} = {};", item); + + ctx.pushScope(item); + type.generate(ctx); + ctx.popScope(); + } + + if (isHash) { + ctx.pushCode("{0}[{2}.{1}] = {2};", lhs, key, item); + } else { + ctx.pushCode("{0}.push({1});", lhs, item); + } + + ctx.pushCode("}"); + + if (typeof this.options.readUntil === "function") { + ctx.pushCode( + " while (!({0}).call(this, {1}, buffer.slice(offset)));", + this.options.readUntil, + item); + + } +}; + +Parser.prototype.generateChoiceCase = function (ctx, varName, type) { + if (typeof type === "string") { + if (!aliasRegistry[type]) { + ctx.pushCode( + "{0} = buffer.read{1}(offset);", + ctx.generateVariable(this.varName), + NAME_MAP[type]); + + ctx.pushCode("offset += {0};", PRIMITIVE_TYPES[NAME_MAP[type]]); + } else { + var tempVar = ctx.generateTmpVariable(); + ctx.pushCode("var {0} = {1}(offset);", tempVar, FUNCTION_PREFIX + type); + ctx.pushCode( + "{0} = {1}.result; offset = {1}.offset;", + ctx.generateVariable(this.varName), + tempVar); + + if (type !== this.alias) ctx.addReference(type); + } + } else if (type instanceof Parser) { + ctx.pushPath(varName); + type.generate(ctx); + ctx.popPath(varName); + } +}; + +Parser.prototype.generateChoice = function (ctx) { + var tag = ctx.generateOption(this.options.tag); + if (this.varName) { + ctx.pushCode("{0} = {};", ctx.generateVariable(this.varName)); + } + ctx.pushCode("switch({0}) {", tag); + Object.keys(this.options.choices).forEach(function (t) { + var type = this.options.choices[t]; + if (Number.isNaN(parseInt(t, 10))) { + ctx.pushCode("case '{0}':", t); + } else { + ctx.pushCode("case {0}:", t); + } + this.generateChoiceCase(ctx, this.varName, type); + ctx.pushCode("break;"); + }, this); + ctx.pushCode("default:"); + if (this.options.defaultChoice) { + this.generateChoiceCase(ctx, this.varName, this.options.defaultChoice); + } else { + ctx.generateError('"Met undefined tag value " + {0} + " at choice"', tag); + } + ctx.pushCode("}"); +}; + +Parser.prototype.generateNest = function (ctx) { + var nestVar = ctx.generateVariable(this.varName); + + if (this.options.type instanceof Parser) { + if (this.varName) { + ctx.pushCode("{0} = {};", nestVar); + } + ctx.pushPath(this.varName); + this.options.type.generate(ctx); + ctx.popPath(this.varName); + } else if (aliasRegistry[this.options.type]) { + var tempVar = ctx.generateTmpVariable(); + ctx.pushCode( + "var {0} = {1}(offset);", + tempVar, + FUNCTION_PREFIX + this.options.type); + + ctx.pushCode("{0} = {1}.result; offset = {1}.offset;", nestVar, tempVar); + if (this.options.type !== this.alias) ctx.addReference(this.options.type); + } +}; + +Parser.prototype.generateFormatter = function (ctx, varName, formatter) { + if (typeof formatter === "function") { + ctx.pushCode("{0} = ({1}).call(this, {0});", varName, formatter); + } +}; + +Parser.prototype.isInteger = function () { + return !!this.type.match(/U?Int[8|16|32][BE|LE]?|Bit\d+/); +}; + +// /////////////////// CRAM-specific types ////////////////////////// +// +Parser.prototype.itf8 = function (varName, options) { + return this.setNextParser("itf8", varName, options); +}; +Parser.prototype.itf8 = function (varName, options) { + return this.setNextParser("itf8", varName, options); +}; + +Parser.prototype.generateItf8 = function (ctx) { + var name = ctx.generateVariable(this.varName); + var countFlags = ctx.generateTmpVariable(); + ctx.pushCode("\n var ".concat( + countFlags, " = buffer[offset];\n if (").concat( + countFlags, " < 0x80) {\n ").concat( + name, " = ").concat(countFlags, ";\n offset += 1;\n } else if (").concat( + + countFlags, " < 0xc0) {\n ").concat( + name, " = ((").concat(countFlags, "<<8) | buffer[offset+1]) & 0x3fff;\n offset += 2;\n } else if (").concat( + + countFlags, " < 0xe0) {\n ").concat( + name, " = ((").concat(countFlags, "<<16) | (buffer[offset+1]<< 8) | buffer[offset+2]) & 0x1fffff;\n offset += 3;\n } else if (").concat( + + countFlags, " < 0xf0) {\n ").concat( + name, " = ((").concat(countFlags, "<<24) | (buffer[offset+1]<<16) | (buffer[offset+2]<<8) | buffer[offset+3]) & 0x0fffffff;\n offset += 4\n } else {\n ").concat( + + + name, " = ((").concat(countFlags, " & 0x0f)<<28) | (buffer[offset+1]<<20) | (buffer[offset+2]<<12) | (buffer[offset+3]<<4) | (buffer[offset+4] & 0x0f);\n // x=((0xff & 0x0f)<<28) | (0xff<<20) | (0xff<<12) | (0xff<<4) | (0x0f & 0x0f);\n // TODO *val_p = uv < 0x80000000UL ? uv : -((int32_t) (0xffffffffUL - uv)) - 1;\n offset += 5\n }\n ")); + + + + + +}; + +Parser.prototype.ltf8 = function (varName, options) { + return this.setNextParser("ltf8", varName, options); +}; + +Parser.prototype.generateLtf8 = function (ctx) { + var name = ctx.generateVariable(this.varName); + var countFlags = ctx.generateTmpVariable(); + ctx.pushCode("\n var ".concat( + countFlags, " = buffer[offset];\n if (").concat( + countFlags, " < 0x80) {\n ").concat( + name, " = ").concat(countFlags, ";\n offset += 1;\n } else if (").concat( + + countFlags, " < 0xc0) {\n ").concat( + name, " = ((buffer[offset]<<8) | buffer[offset+1]) & 0x3fff;\n offset += 2;\n } else if (").concat( + + countFlags, " < 0xe0) {\n ").concat( + name, " = ((buffer[offset]<<16) | (buffer[offset+1]<<8) | buffer[offset+2]) & 0x1fffff;\n ").concat( + name, " = (((").concat(countFlags, " & 63) << 16) | buffer.readUInt16LE(offset + 1));\n offset += 3;\n } else if (").concat( + + countFlags, " < 0xf0) {\n ").concat( + name, " = ((buffer[offset]<<24) | (buffer[offset+1]<<16) | (buffer[offset+2]<<8) | buffer[offset+3]) & 0x0fffffff;\n offset += 4;\n } else if (").concat( + + countFlags, " < 0xf8) {\n ").concat( + name, " = (((buffer[offset] & 15) * Math.pow(2,32))) +\n (buffer[offset+1]<<24) | (buffer[offset+2]<<16 | buffer[offset+3]<<8 | buffer[offset+4])\n // TODO *val_p = uv < 0x80000000UL ? uv : -((int32_t) (0xffffffffUL - uv)) - 1;\n offset += 5;\n } else if (").concat( + + + + countFlags, " < 0xfc) {\n ").concat( + name, " = ((((buffer[offset] & 7) << 8) | buffer[offset+1] )) * Math.pow(2,32) +\n (buffer[offset+2]<<24) | (buffer[offset+3]<<16 | buffer[offset+4]<<8 | buffer[offset+5])\n offset += 6;\n } else if (").concat( + + + countFlags, " < 0xfe) {\n ").concat( + name, " = ((((buffer[offset] & 3) << 16) | buffer[offset+1]<<8 | buffer[offset+2])) * Math.pow(2,32) +\n (buffer[offset+3]<<24) | (buffer[offset+4]<<16 | buffer[offset+5]<<8 | buffer[offset+6])\n offset += 7;\n } else if (").concat( + + + countFlags, " < 0xff) {\n ").concat( + name, " = Long.fromBytesBE(buffer.slice(offset+1,offset+8));\n if (").concat( + name, ".greaterThan(Number.MAX_SAFE_INTEGER) || ").concat(name, ".lessThan(Number.MIN_SAFE_INTEGER))\n throw new Error('integer overflow')\n ").concat( + + name, " = ").concat(name, ".toNumber()\n offset += 8;\n } else {\n ").concat( + + + name, " = Long.fromBytesBE(buffer.slice(offset+1,offset+9));\n if (").concat( + name, ".greaterThan(Number.MAX_SAFE_INTEGER) || ").concat(name, ".lessThan(Number.MIN_SAFE_INTEGER))\n throw new Error('integer overflow')\n ").concat( + + name, " = ").concat(name, ".toNumber()\n offset += 9;\n }\n ")); + + + +}; + +//= ======================================================================================= +// Exports +//= ======================================================================================= + +exports._ = Parser; + +/***/ }), + +/***/ 2961: +/***/ (function(__unused_webpack_module, exports) { + +"use strict"; +function _typeof(obj) {if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {_typeof = function _typeof(obj) {return typeof obj;};} else {_typeof = function _typeof(obj) {return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;};}return _typeof(obj);} //= ======================================================================================= +// class Context +//= ======================================================================================= + +//---------------------------------------------------------------------------------------- +// constructor +//---------------------------------------------------------------------------------------- + +var Context = function Context() { + this.code = ""; + this.scopes = [["vars"]]; + this.isAsync = false; + this.bitFields = []; + this.tmpVariableCount = 0; + this.references = {}; +}; + +//---------------------------------------------------------------------------------------- +// public methods +//---------------------------------------------------------------------------------------- + +Context.prototype.generateVariable = function (name) { + var arr = []; + + Array.prototype.push.apply(arr, this.scopes[this.scopes.length - 1]); + + // $parent. prefixes allow sub-parsers to access values of their parent parsers + while (/^\$parent\./.test(name)) { + arr.pop(); + name = name.replace(/^\$parent\./, ""); + } + + if (name) { + arr.push(name); + } + + return arr.join("."); +}; + +Context.prototype.generateOption = function (val) { + switch (_typeof(val)) { + case "number": + return val.toString(); + case "string": + return this.generateVariable(val); + case "function": + return "(".concat(val, ").call(").concat(this.generateVariable(), ", vars)"); + default: + return undefined;} + +}; + +Context.prototype.generateError = function () { + var args = Array.prototype.slice.call(arguments); + var err = Context.interpolate.apply(this, args); + + if (this.isAsync) { + this.pushCode("return process.nextTick(function() { callback(new Error(".concat( + err, "), vars); });")); + + } else { + this.pushCode("throw new Error(".concat(err, ");")); + } +}; + +Context.prototype.generateTmpVariable = function () { + return "$tmp".concat(this.tmpVariableCount++); +}; + +Context.prototype.pushCode = function () { + var args = Array.prototype.slice.call(arguments); + + this.code += "".concat(Context.interpolate.apply(this, args), "\n"); +}; + +Context.prototype.pushPath = function (name) { + if (name) { + this.scopes[this.scopes.length - 1].push(name); + } +}; + +Context.prototype.popPath = function (name) { + if (name) { + this.scopes[this.scopes.length - 1].pop(); + } +}; + +Context.prototype.pushScope = function (name) { + this.scopes.push([name]); +}; + +Context.prototype.popScope = function () { + this.scopes.pop(); +}; + +Context.prototype.addReference = function (alias) { + if (this.references[alias]) return; + this.references[alias] = { resolved: false, requested: false }; +}; + +Context.prototype.markResolved = function (alias) { + this.references[alias].resolved = true; +}; + +Context.prototype.markRequested = function (aliasList) { + aliasList.forEach( + function (alias) { + this.references[alias].requested = true; + }.bind(this)); + +}; + +Context.prototype.getUnresolvedReferences = function () { + var references = this.references; + return Object.keys(this.references).filter(function (alias) { + return !references[alias].resolved && !references[alias].requested; + }); +}; + +//---------------------------------------------------------------------------------------- +// private methods +//---------------------------------------------------------------------------------------- + +Context.interpolate = function (s) { + var re = /{\d+}/g; + var matches = s.match(re); + var params = Array.prototype.slice.call(arguments, 1); + + if (matches) { + matches.forEach(function (match) { + var index = parseInt(match.substr(1, match.length - 2), 10); + s = s.replace(match, params[index].toString()); + }); + } + + return s; +}; + +exports._ = Context; + +/***/ }), + +/***/ 22: +/***/ (function(module) { + +// https://github.com/ionic-team/rollup-plugin-node-polyfills/blob/9b5fe1a9cafffd4871e6d65613ed224f807ea251/polyfills/vm.js#L129-L132 +function runInThisContext(code) { + const fn = new Function('code', 'return eval(code);'); + return fn.call(globalThis, code); +} + +module.exports.runInThisContext = runInThisContext; + + +/***/ }), + +/***/ 3720: +/***/ (function(module) { + +module.exports = Long; + +/** + * wasm optimizations, to do native i64 multiplication and divide + */ +var wasm = null; + +try { + wasm = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([ + 0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 2, 96, 0, 1, 127, 96, 4, 127, 127, 127, 127, 1, 127, 3, 7, 6, 0, 1, 1, 1, 1, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 50, 6, 3, 109, 117, 108, 0, 1, 5, 100, 105, 118, 95, 115, 0, 2, 5, 100, 105, 118, 95, 117, 0, 3, 5, 114, 101, 109, 95, 115, 0, 4, 5, 114, 101, 109, 95, 117, 0, 5, 8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0, 10, 191, 1, 6, 4, 0, 35, 0, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11 + ])), {}).exports; +} catch (e) { + // no wasm support :( +} + +/** + * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers. + * See the from* functions below for more convenient ways of constructing Longs. + * @exports Long + * @class A Long class for representing a 64 bit two's-complement integer value. + * @param {number} low The low (signed) 32 bits of the long + * @param {number} high The high (signed) 32 bits of the long + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @constructor + */ +function Long(low, high, unsigned) { + + /** + * The low 32 bits as a signed value. + * @type {number} + */ + this.low = low | 0; + + /** + * The high 32 bits as a signed value. + * @type {number} + */ + this.high = high | 0; + + /** + * Whether unsigned or not. + * @type {boolean} + */ + this.unsigned = !!unsigned; +} + +// The internal representation of a long is the two given signed, 32-bit values. +// We use 32-bit pieces because these are the size of integers on which +// Javascript performs bit-operations. For operations like addition and +// multiplication, we split each number into 16 bit pieces, which can easily be +// multiplied within Javascript's floating-point representation without overflow +// or change in sign. +// +// In the algorithms below, we frequently reduce the negative case to the +// positive case by negating the input(s) and then post-processing the result. +// Note that we must ALWAYS check specially whether those values are MIN_VALUE +// (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as +// a positive number, it overflows back into a negative). Not handling this +// case would often result in infinite recursion. +// +// Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from* +// methods on which they depend. + +/** + * An indicator used to reliably determine if an object is a Long or not. + * @type {boolean} + * @const + * @private + */ +Long.prototype.__isLong__; + +Object.defineProperty(Long.prototype, "__isLong__", { value: true }); + +/** + * @function + * @param {*} obj Object + * @returns {boolean} + * @inner + */ +function isLong(obj) { + return (obj && obj["__isLong__"]) === true; +} + +/** + * Tests if the specified object is a Long. + * @function + * @param {*} obj Object + * @returns {boolean} + */ +Long.isLong = isLong; + +/** + * A cache of the Long representations of small integer values. + * @type {!Object} + * @inner + */ +var INT_CACHE = {}; + +/** + * A cache of the Long representations of small unsigned integer values. + * @type {!Object} + * @inner + */ +var UINT_CACHE = {}; + +/** + * @param {number} value + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + */ +function fromInt(value, unsigned) { + var obj, cachedObj, cache; + if (unsigned) { + value >>>= 0; + if (cache = (0 <= value && value < 256)) { + cachedObj = UINT_CACHE[value]; + if (cachedObj) + return cachedObj; + } + obj = fromBits(value, (value | 0) < 0 ? -1 : 0, true); + if (cache) + UINT_CACHE[value] = obj; + return obj; + } else { + value |= 0; + if (cache = (-128 <= value && value < 128)) { + cachedObj = INT_CACHE[value]; + if (cachedObj) + return cachedObj; + } + obj = fromBits(value, value < 0 ? -1 : 0, false); + if (cache) + INT_CACHE[value] = obj; + return obj; + } +} + +/** + * Returns a Long representing the given 32 bit integer value. + * @function + * @param {number} value The 32 bit integer in question + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {!Long} The corresponding Long value + */ +Long.fromInt = fromInt; + +/** + * @param {number} value + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + */ +function fromNumber(value, unsigned) { + if (isNaN(value)) + return unsigned ? UZERO : ZERO; + if (unsigned) { + if (value < 0) + return UZERO; + if (value >= TWO_PWR_64_DBL) + return MAX_UNSIGNED_VALUE; + } else { + if (value <= -TWO_PWR_63_DBL) + return MIN_VALUE; + if (value + 1 >= TWO_PWR_63_DBL) + return MAX_VALUE; + } + if (value < 0) + return fromNumber(-value, unsigned).neg(); + return fromBits((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned); +} + +/** + * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned. + * @function + * @param {number} value The number in question + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {!Long} The corresponding Long value + */ +Long.fromNumber = fromNumber; + +/** + * @param {number} lowBits + * @param {number} highBits + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + */ +function fromBits(lowBits, highBits, unsigned) { + return new Long(lowBits, highBits, unsigned); +} + +/** + * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is + * assumed to use 32 bits. + * @function + * @param {number} lowBits The low 32 bits + * @param {number} highBits The high 32 bits + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {!Long} The corresponding Long value + */ +Long.fromBits = fromBits; + +/** + * @function + * @param {number} base + * @param {number} exponent + * @returns {number} + * @inner + */ +var pow_dbl = Math.pow; // Used 4 times (4*8 to 15+4) + +/** + * @param {string} str + * @param {(boolean|number)=} unsigned + * @param {number=} radix + * @returns {!Long} + * @inner + */ +function fromString(str, unsigned, radix) { + if (str.length === 0) + throw Error('empty string'); + if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity") + return ZERO; + if (typeof unsigned === 'number') { + // For goog.math.long compatibility + radix = unsigned, + unsigned = false; + } else { + unsigned = !! unsigned; + } + radix = radix || 10; + if (radix < 2 || 36 < radix) + throw RangeError('radix'); + + var p; + if ((p = str.indexOf('-')) > 0) + throw Error('interior hyphen'); + else if (p === 0) { + return fromString(str.substring(1), unsigned, radix).neg(); + } + + // Do several (8) digits each time through the loop, so as to + // minimize the calls to the very expensive emulated div. + var radixToPower = fromNumber(pow_dbl(radix, 8)); + + var result = ZERO; + for (var i = 0; i < str.length; i += 8) { + var size = Math.min(8, str.length - i), + value = parseInt(str.substring(i, i + size), radix); + if (size < 8) { + var power = fromNumber(pow_dbl(radix, size)); + result = result.mul(power).add(fromNumber(value)); + } else { + result = result.mul(radixToPower); + result = result.add(fromNumber(value)); + } + } + result.unsigned = unsigned; + return result; +} + +/** + * Returns a Long representation of the given string, written using the specified radix. + * @function + * @param {string} str The textual representation of the Long + * @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to signed + * @param {number=} radix The radix in which the text is written (2-36), defaults to 10 + * @returns {!Long} The corresponding Long value + */ +Long.fromString = fromString; + +/** + * @function + * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + */ +function fromValue(val, unsigned) { + if (typeof val === 'number') + return fromNumber(val, unsigned); + if (typeof val === 'string') + return fromString(val, unsigned); + // Throws for non-objects, converts non-instanceof Long: + return fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned); +} + +/** + * Converts the specified value to a Long using the appropriate from* function for its type. + * @function + * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {!Long} + */ +Long.fromValue = fromValue; + +// NOTE: the compiler should inline these constant values below and then remove these variables, so there should be +// no runtime penalty for these. + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_16_DBL = 1 << 16; + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_24_DBL = 1 << 24; + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL; + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL; + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2; + +/** + * @type {!Long} + * @const + * @inner + */ +var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL); + +/** + * @type {!Long} + * @inner + */ +var ZERO = fromInt(0); + +/** + * Signed zero. + * @type {!Long} + */ +Long.ZERO = ZERO; + +/** + * @type {!Long} + * @inner + */ +var UZERO = fromInt(0, true); + +/** + * Unsigned zero. + * @type {!Long} + */ +Long.UZERO = UZERO; + +/** + * @type {!Long} + * @inner + */ +var ONE = fromInt(1); + +/** + * Signed one. + * @type {!Long} + */ +Long.ONE = ONE; + +/** + * @type {!Long} + * @inner + */ +var UONE = fromInt(1, true); + +/** + * Unsigned one. + * @type {!Long} + */ +Long.UONE = UONE; + +/** + * @type {!Long} + * @inner + */ +var NEG_ONE = fromInt(-1); + +/** + * Signed negative one. + * @type {!Long} + */ +Long.NEG_ONE = NEG_ONE; + +/** + * @type {!Long} + * @inner + */ +var MAX_VALUE = fromBits(0xFFFFFFFF|0, 0x7FFFFFFF|0, false); + +/** + * Maximum signed value. + * @type {!Long} + */ +Long.MAX_VALUE = MAX_VALUE; + +/** + * @type {!Long} + * @inner + */ +var MAX_UNSIGNED_VALUE = fromBits(0xFFFFFFFF|0, 0xFFFFFFFF|0, true); + +/** + * Maximum unsigned value. + * @type {!Long} + */ +Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE; + +/** + * @type {!Long} + * @inner + */ +var MIN_VALUE = fromBits(0, 0x80000000|0, false); + +/** + * Minimum signed value. + * @type {!Long} + */ +Long.MIN_VALUE = MIN_VALUE; + +/** + * @alias Long.prototype + * @inner + */ +var LongPrototype = Long.prototype; + +/** + * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. + * @returns {number} + */ +LongPrototype.toInt = function toInt() { + return this.unsigned ? this.low >>> 0 : this.low; +}; + +/** + * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). + * @returns {number} + */ +LongPrototype.toNumber = function toNumber() { + if (this.unsigned) + return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0); + return this.high * TWO_PWR_32_DBL + (this.low >>> 0); +}; + +/** + * Converts the Long to a string written in the specified radix. + * @param {number=} radix Radix (2-36), defaults to 10 + * @returns {string} + * @override + * @throws {RangeError} If `radix` is out of range + */ +LongPrototype.toString = function toString(radix) { + radix = radix || 10; + if (radix < 2 || 36 < radix) + throw RangeError('radix'); + if (this.isZero()) + return '0'; + if (this.isNegative()) { // Unsigned Longs are never negative + if (this.eq(MIN_VALUE)) { + // We need to change the Long value before it can be negated, so we remove + // the bottom-most digit in this base and then recurse to do the rest. + var radixLong = fromNumber(radix), + div = this.div(radixLong), + rem1 = div.mul(radixLong).sub(this); + return div.toString(radix) + rem1.toInt().toString(radix); + } else + return '-' + this.neg().toString(radix); + } + + // Do several (6) digits each time through the loop, so as to + // minimize the calls to the very expensive emulated div. + var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned), + rem = this; + var result = ''; + while (true) { + var remDiv = rem.div(radixToPower), + intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0, + digits = intval.toString(radix); + rem = remDiv; + if (rem.isZero()) + return digits + result; + else { + while (digits.length < 6) + digits = '0' + digits; + result = '' + digits + result; + } + } +}; + +/** + * Gets the high 32 bits as a signed integer. + * @returns {number} Signed high bits + */ +LongPrototype.getHighBits = function getHighBits() { + return this.high; +}; + +/** + * Gets the high 32 bits as an unsigned integer. + * @returns {number} Unsigned high bits + */ +LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() { + return this.high >>> 0; +}; + +/** + * Gets the low 32 bits as a signed integer. + * @returns {number} Signed low bits + */ +LongPrototype.getLowBits = function getLowBits() { + return this.low; +}; + +/** + * Gets the low 32 bits as an unsigned integer. + * @returns {number} Unsigned low bits + */ +LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() { + return this.low >>> 0; +}; + +/** + * Gets the number of bits needed to represent the absolute value of this Long. + * @returns {number} + */ +LongPrototype.getNumBitsAbs = function getNumBitsAbs() { + if (this.isNegative()) // Unsigned Longs are never negative + return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs(); + var val = this.high != 0 ? this.high : this.low; + for (var bit = 31; bit > 0; bit--) + if ((val & (1 << bit)) != 0) + break; + return this.high != 0 ? bit + 33 : bit + 1; +}; + +/** + * Tests if this Long's value equals zero. + * @returns {boolean} + */ +LongPrototype.isZero = function isZero() { + return this.high === 0 && this.low === 0; +}; + +/** + * Tests if this Long's value equals zero. This is an alias of {@link Long#isZero}. + * @returns {boolean} + */ +LongPrototype.eqz = LongPrototype.isZero; + +/** + * Tests if this Long's value is negative. + * @returns {boolean} + */ +LongPrototype.isNegative = function isNegative() { + return !this.unsigned && this.high < 0; +}; + +/** + * Tests if this Long's value is positive. + * @returns {boolean} + */ +LongPrototype.isPositive = function isPositive() { + return this.unsigned || this.high >= 0; +}; + +/** + * Tests if this Long's value is odd. + * @returns {boolean} + */ +LongPrototype.isOdd = function isOdd() { + return (this.low & 1) === 1; +}; + +/** + * Tests if this Long's value is even. + * @returns {boolean} + */ +LongPrototype.isEven = function isEven() { + return (this.low & 1) === 0; +}; + +/** + * Tests if this Long's value equals the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.equals = function equals(other) { + if (!isLong(other)) + other = fromValue(other); + if (this.unsigned !== other.unsigned && (this.high >>> 31) === 1 && (other.high >>> 31) === 1) + return false; + return this.high === other.high && this.low === other.low; +}; + +/** + * Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.eq = LongPrototype.equals; + +/** + * Tests if this Long's value differs from the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.notEquals = function notEquals(other) { + return !this.eq(/* validates */ other); +}; + +/** + * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.neq = LongPrototype.notEquals; + +/** + * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.ne = LongPrototype.notEquals; + +/** + * Tests if this Long's value is less than the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.lessThan = function lessThan(other) { + return this.comp(/* validates */ other) < 0; +}; + +/** + * Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.lt = LongPrototype.lessThan; + +/** + * Tests if this Long's value is less than or equal the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) { + return this.comp(/* validates */ other) <= 0; +}; + +/** + * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.lte = LongPrototype.lessThanOrEqual; + +/** + * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.le = LongPrototype.lessThanOrEqual; + +/** + * Tests if this Long's value is greater than the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.greaterThan = function greaterThan(other) { + return this.comp(/* validates */ other) > 0; +}; + +/** + * Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.gt = LongPrototype.greaterThan; + +/** + * Tests if this Long's value is greater than or equal the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) { + return this.comp(/* validates */ other) >= 0; +}; + +/** + * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.gte = LongPrototype.greaterThanOrEqual; + +/** + * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.ge = LongPrototype.greaterThanOrEqual; + +/** + * Compares this Long's value with the specified's. + * @param {!Long|number|string} other Other value + * @returns {number} 0 if they are the same, 1 if the this is greater and -1 + * if the given one is greater + */ +LongPrototype.compare = function compare(other) { + if (!isLong(other)) + other = fromValue(other); + if (this.eq(other)) + return 0; + var thisNeg = this.isNegative(), + otherNeg = other.isNegative(); + if (thisNeg && !otherNeg) + return -1; + if (!thisNeg && otherNeg) + return 1; + // At this point the sign bits are the same + if (!this.unsigned) + return this.sub(other).isNegative() ? -1 : 1; + // Both are positive if at least one is unsigned + return (other.high >>> 0) > (this.high >>> 0) || (other.high === this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1; +}; + +/** + * Compares this Long's value with the specified's. This is an alias of {@link Long#compare}. + * @function + * @param {!Long|number|string} other Other value + * @returns {number} 0 if they are the same, 1 if the this is greater and -1 + * if the given one is greater + */ +LongPrototype.comp = LongPrototype.compare; + +/** + * Negates this Long's value. + * @returns {!Long} Negated Long + */ +LongPrototype.negate = function negate() { + if (!this.unsigned && this.eq(MIN_VALUE)) + return MIN_VALUE; + return this.not().add(ONE); +}; + +/** + * Negates this Long's value. This is an alias of {@link Long#negate}. + * @function + * @returns {!Long} Negated Long + */ +LongPrototype.neg = LongPrototype.negate; + +/** + * Returns the sum of this and the specified Long. + * @param {!Long|number|string} addend Addend + * @returns {!Long} Sum + */ +LongPrototype.add = function add(addend) { + if (!isLong(addend)) + addend = fromValue(addend); + + // Divide each number into 4 chunks of 16 bits, and then sum the chunks. + + var a48 = this.high >>> 16; + var a32 = this.high & 0xFFFF; + var a16 = this.low >>> 16; + var a00 = this.low & 0xFFFF; + + var b48 = addend.high >>> 16; + var b32 = addend.high & 0xFFFF; + var b16 = addend.low >>> 16; + var b00 = addend.low & 0xFFFF; + + var c48 = 0, c32 = 0, c16 = 0, c00 = 0; + c00 += a00 + b00; + c16 += c00 >>> 16; + c00 &= 0xFFFF; + c16 += a16 + b16; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c32 += a32 + b32; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c48 += a48 + b48; + c48 &= 0xFFFF; + return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); +}; + +/** + * Returns the difference of this and the specified Long. + * @param {!Long|number|string} subtrahend Subtrahend + * @returns {!Long} Difference + */ +LongPrototype.subtract = function subtract(subtrahend) { + if (!isLong(subtrahend)) + subtrahend = fromValue(subtrahend); + return this.add(subtrahend.neg()); +}; + +/** + * Returns the difference of this and the specified Long. This is an alias of {@link Long#subtract}. + * @function + * @param {!Long|number|string} subtrahend Subtrahend + * @returns {!Long} Difference + */ +LongPrototype.sub = LongPrototype.subtract; + +/** + * Returns the product of this and the specified Long. + * @param {!Long|number|string} multiplier Multiplier + * @returns {!Long} Product + */ +LongPrototype.multiply = function multiply(multiplier) { + if (this.isZero()) + return ZERO; + if (!isLong(multiplier)) + multiplier = fromValue(multiplier); + + // use wasm support if present + if (wasm) { + var low = wasm.mul(this.low, + this.high, + multiplier.low, + multiplier.high); + return fromBits(low, wasm.get_high(), this.unsigned); + } + + if (multiplier.isZero()) + return ZERO; + if (this.eq(MIN_VALUE)) + return multiplier.isOdd() ? MIN_VALUE : ZERO; + if (multiplier.eq(MIN_VALUE)) + return this.isOdd() ? MIN_VALUE : ZERO; + + if (this.isNegative()) { + if (multiplier.isNegative()) + return this.neg().mul(multiplier.neg()); + else + return this.neg().mul(multiplier).neg(); + } else if (multiplier.isNegative()) + return this.mul(multiplier.neg()).neg(); + + // If both longs are small, use float multiplication + if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24)) + return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned); + + // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products. + // We can skip products that would overflow. + + var a48 = this.high >>> 16; + var a32 = this.high & 0xFFFF; + var a16 = this.low >>> 16; + var a00 = this.low & 0xFFFF; + + var b48 = multiplier.high >>> 16; + var b32 = multiplier.high & 0xFFFF; + var b16 = multiplier.low >>> 16; + var b00 = multiplier.low & 0xFFFF; + + var c48 = 0, c32 = 0, c16 = 0, c00 = 0; + c00 += a00 * b00; + c16 += c00 >>> 16; + c00 &= 0xFFFF; + c16 += a16 * b00; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c16 += a00 * b16; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c32 += a32 * b00; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c32 += a16 * b16; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c32 += a00 * b32; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48; + c48 &= 0xFFFF; + return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); +}; + +/** + * Returns the product of this and the specified Long. This is an alias of {@link Long#multiply}. + * @function + * @param {!Long|number|string} multiplier Multiplier + * @returns {!Long} Product + */ +LongPrototype.mul = LongPrototype.multiply; + +/** + * Returns this Long divided by the specified. The result is signed if this Long is signed or + * unsigned if this Long is unsigned. + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Quotient + */ +LongPrototype.divide = function divide(divisor) { + if (!isLong(divisor)) + divisor = fromValue(divisor); + if (divisor.isZero()) + throw Error('division by zero'); + + // use wasm support if present + if (wasm) { + // guard against signed division overflow: the largest + // negative number / -1 would be 1 larger than the largest + // positive number, due to two's complement. + if (!this.unsigned && + this.high === -0x80000000 && + divisor.low === -1 && divisor.high === -1) { + // be consistent with non-wasm code path + return this; + } + var low = (this.unsigned ? wasm.div_u : wasm.div_s)( + this.low, + this.high, + divisor.low, + divisor.high + ); + return fromBits(low, wasm.get_high(), this.unsigned); + } + + if (this.isZero()) + return this.unsigned ? UZERO : ZERO; + var approx, rem, res; + if (!this.unsigned) { + // This section is only relevant for signed longs and is derived from the + // closure library as a whole. + if (this.eq(MIN_VALUE)) { + if (divisor.eq(ONE) || divisor.eq(NEG_ONE)) + return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE + else if (divisor.eq(MIN_VALUE)) + return ONE; + else { + // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|. + var halfThis = this.shr(1); + approx = halfThis.div(divisor).shl(1); + if (approx.eq(ZERO)) { + return divisor.isNegative() ? ONE : NEG_ONE; + } else { + rem = this.sub(divisor.mul(approx)); + res = approx.add(rem.div(divisor)); + return res; + } + } + } else if (divisor.eq(MIN_VALUE)) + return this.unsigned ? UZERO : ZERO; + if (this.isNegative()) { + if (divisor.isNegative()) + return this.neg().div(divisor.neg()); + return this.neg().div(divisor).neg(); + } else if (divisor.isNegative()) + return this.div(divisor.neg()).neg(); + res = ZERO; + } else { + // The algorithm below has not been made for unsigned longs. It's therefore + // required to take special care of the MSB prior to running it. + if (!divisor.unsigned) + divisor = divisor.toUnsigned(); + if (divisor.gt(this)) + return UZERO; + if (divisor.gt(this.shru(1))) // 15 >>> 1 = 7 ; with divisor = 8 ; true + return UONE; + res = UZERO; + } + + // Repeat the following until the remainder is less than other: find a + // floating-point that approximates remainder / other *from below*, add this + // into the result, and subtract it from the remainder. It is critical that + // the approximate value is less than or equal to the real value so that the + // remainder never becomes negative. + rem = this; + while (rem.gte(divisor)) { + // Approximate the result of division. This may be a little greater or + // smaller than the actual value. + approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber())); + + // We will tweak the approximate result by changing it in the 48-th digit or + // the smallest non-fractional digit, whichever is larger. + var log2 = Math.ceil(Math.log(approx) / Math.LN2), + delta = (log2 <= 48) ? 1 : pow_dbl(2, log2 - 48), + + // Decrease the approximation until it is smaller than the remainder. Note + // that if it is too large, the product overflows and is negative. + approxRes = fromNumber(approx), + approxRem = approxRes.mul(divisor); + while (approxRem.isNegative() || approxRem.gt(rem)) { + approx -= delta; + approxRes = fromNumber(approx, this.unsigned); + approxRem = approxRes.mul(divisor); + } + + // We know the answer can't be zero... and actually, zero would cause + // infinite recursion since we would make no progress. + if (approxRes.isZero()) + approxRes = ONE; + + res = res.add(approxRes); + rem = rem.sub(approxRem); + } + return res; +}; + +/** + * Returns this Long divided by the specified. This is an alias of {@link Long#divide}. + * @function + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Quotient + */ +LongPrototype.div = LongPrototype.divide; + +/** + * Returns this Long modulo the specified. + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Remainder + */ +LongPrototype.modulo = function modulo(divisor) { + if (!isLong(divisor)) + divisor = fromValue(divisor); + + // use wasm support if present + if (wasm) { + var low = (this.unsigned ? wasm.rem_u : wasm.rem_s)( + this.low, + this.high, + divisor.low, + divisor.high + ); + return fromBits(low, wasm.get_high(), this.unsigned); + } + + return this.sub(this.div(divisor).mul(divisor)); +}; + +/** + * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}. + * @function + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Remainder + */ +LongPrototype.mod = LongPrototype.modulo; + +/** + * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}. + * @function + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Remainder + */ +LongPrototype.rem = LongPrototype.modulo; + +/** + * Returns the bitwise NOT of this Long. + * @returns {!Long} + */ +LongPrototype.not = function not() { + return fromBits(~this.low, ~this.high, this.unsigned); +}; + +/** + * Returns the bitwise AND of this Long and the specified. + * @param {!Long|number|string} other Other Long + * @returns {!Long} + */ +LongPrototype.and = function and(other) { + if (!isLong(other)) + other = fromValue(other); + return fromBits(this.low & other.low, this.high & other.high, this.unsigned); +}; + +/** + * Returns the bitwise OR of this Long and the specified. + * @param {!Long|number|string} other Other Long + * @returns {!Long} + */ +LongPrototype.or = function or(other) { + if (!isLong(other)) + other = fromValue(other); + return fromBits(this.low | other.low, this.high | other.high, this.unsigned); +}; + +/** + * Returns the bitwise XOR of this Long and the given one. + * @param {!Long|number|string} other Other Long + * @returns {!Long} + */ +LongPrototype.xor = function xor(other) { + if (!isLong(other)) + other = fromValue(other); + return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned); +}; + +/** + * Returns this Long with bits shifted to the left by the given amount. + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shiftLeft = function shiftLeft(numBits) { + if (isLong(numBits)) + numBits = numBits.toInt(); + if ((numBits &= 63) === 0) + return this; + else if (numBits < 32) + return fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned); + else + return fromBits(0, this.low << (numBits - 32), this.unsigned); +}; + +/** + * Returns this Long with bits shifted to the left by the given amount. This is an alias of {@link Long#shiftLeft}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shl = LongPrototype.shiftLeft; + +/** + * Returns this Long with bits arithmetically shifted to the right by the given amount. + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shiftRight = function shiftRight(numBits) { + if (isLong(numBits)) + numBits = numBits.toInt(); + if ((numBits &= 63) === 0) + return this; + else if (numBits < 32) + return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned); + else + return fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned); +}; + +/** + * Returns this Long with bits arithmetically shifted to the right by the given amount. This is an alias of {@link Long#shiftRight}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shr = LongPrototype.shiftRight; + +/** + * Returns this Long with bits logically shifted to the right by the given amount. + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) { + if (isLong(numBits)) + numBits = numBits.toInt(); + numBits &= 63; + if (numBits === 0) + return this; + else { + var high = this.high; + if (numBits < 32) { + var low = this.low; + return fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned); + } else if (numBits === 32) + return fromBits(high, 0, this.unsigned); + else + return fromBits(high >>> (numBits - 32), 0, this.unsigned); + } +}; + +/** + * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shru = LongPrototype.shiftRightUnsigned; + +/** + * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shr_u = LongPrototype.shiftRightUnsigned; + +/** + * Converts this Long to signed. + * @returns {!Long} Signed long + */ +LongPrototype.toSigned = function toSigned() { + if (!this.unsigned) + return this; + return fromBits(this.low, this.high, false); +}; + +/** + * Converts this Long to unsigned. + * @returns {!Long} Unsigned long + */ +LongPrototype.toUnsigned = function toUnsigned() { + if (this.unsigned) + return this; + return fromBits(this.low, this.high, true); +}; + +/** + * Converts this Long to its byte representation. + * @param {boolean=} le Whether little or big endian, defaults to big endian + * @returns {!Array.} Byte representation + */ +LongPrototype.toBytes = function toBytes(le) { + return le ? this.toBytesLE() : this.toBytesBE(); +}; + +/** + * Converts this Long to its little endian byte representation. + * @returns {!Array.} Little endian byte representation + */ +LongPrototype.toBytesLE = function toBytesLE() { + var hi = this.high, + lo = this.low; + return [ + lo & 0xff, + lo >>> 8 & 0xff, + lo >>> 16 & 0xff, + lo >>> 24 , + hi & 0xff, + hi >>> 8 & 0xff, + hi >>> 16 & 0xff, + hi >>> 24 + ]; +}; + +/** + * Converts this Long to its big endian byte representation. + * @returns {!Array.} Big endian byte representation + */ +LongPrototype.toBytesBE = function toBytesBE() { + var hi = this.high, + lo = this.low; + return [ + hi >>> 24 , + hi >>> 16 & 0xff, + hi >>> 8 & 0xff, + hi & 0xff, + lo >>> 24 , + lo >>> 16 & 0xff, + lo >>> 8 & 0xff, + lo & 0xff + ]; +}; + +/** + * Creates a Long from its byte representation. + * @param {!Array.} bytes Byte representation + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @param {boolean=} le Whether little or big endian, defaults to big endian + * @returns {Long} The corresponding Long value + */ +Long.fromBytes = function fromBytes(bytes, unsigned, le) { + return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned); +}; + +/** + * Creates a Long from its little endian byte representation. + * @param {!Array.} bytes Little endian byte representation + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {Long} The corresponding Long value + */ +Long.fromBytesLE = function fromBytesLE(bytes, unsigned) { + return new Long( + bytes[0] | + bytes[1] << 8 | + bytes[2] << 16 | + bytes[3] << 24, + bytes[4] | + bytes[5] << 8 | + bytes[6] << 16 | + bytes[7] << 24, + unsigned + ); +}; + +/** + * Creates a Long from its big endian byte representation. + * @param {!Array.} bytes Big endian byte representation + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {Long} The corresponding Long value + */ +Long.fromBytesBE = function fromBytesBE(bytes, unsigned) { + return new Long( + bytes[4] << 24 | + bytes[5] << 16 | + bytes[6] << 8 | + bytes[7], + bytes[0] << 24 | + bytes[1] << 16 | + bytes[2] << 8 | + bytes[3], + unsigned + ); +}; + + +/***/ }), + +/***/ 1876: +/***/ (function(module) { + +var __dirname = "/"; +(function(){var e={675:function(e,r){"use strict";r.byteLength=byteLength;r.toByteArray=toByteArray;r.fromByteArray=fromByteArray;var t=[];var f=[];var n=typeof Uint8Array!=="undefined"?Uint8Array:Array;var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var o=0,u=i.length;o0){throw new Error("Invalid string. Length must be a multiple of 4")}var t=e.indexOf("=");if(t===-1)t=r;var f=t===r?0:4-t%4;return[t,f]}function byteLength(e){var r=getLens(e);var t=r[0];var f=r[1];return(t+f)*3/4-f}function _byteLength(e,r,t){return(r+t)*3/4-t}function toByteArray(e){var r;var t=getLens(e);var i=t[0];var o=t[1];var u=new n(_byteLength(e,i,o));var a=0;var s=o>0?i-4:i;var h;for(h=0;h>16&255;u[a++]=r>>8&255;u[a++]=r&255}if(o===2){r=f[e.charCodeAt(h)]<<2|f[e.charCodeAt(h+1)]>>4;u[a++]=r&255}if(o===1){r=f[e.charCodeAt(h)]<<10|f[e.charCodeAt(h+1)]<<4|f[e.charCodeAt(h+2)]>>2;u[a++]=r>>8&255;u[a++]=r&255}return u}function tripletToBase64(e){return t[e>>18&63]+t[e>>12&63]+t[e>>6&63]+t[e&63]}function encodeChunk(e,r,t){var f;var n=[];for(var i=r;ia?a:u+o))}if(n===1){r=e[f-1];i.push(t[r>>2]+t[r<<4&63]+"==")}else if(n===2){r=(e[f-2]<<8)+e[f-1];i.push(t[r>>10]+t[r>>4&63]+t[r<<2&63]+"=")}return i.join("")}},72:function(e,r,t){"use strict"; +/*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh + * @license MIT + */var f=t(675);var n=t(783);var i=typeof Symbol==="function"&&typeof Symbol.for==="function"?Symbol.for("nodejs.util.inspect.custom"):null;r.Buffer=Buffer;r.SlowBuffer=SlowBuffer;r.INSPECT_MAX_BYTES=50;var o=2147483647;r.kMaxLength=o;Buffer.TYPED_ARRAY_SUPPORT=typedArraySupport();if(!Buffer.TYPED_ARRAY_SUPPORT&&typeof console!=="undefined"&&typeof console.error==="function"){console.error("This browser lacks typed array (Uint8Array) support which is required by "+"`buffer` v5.x. Use `buffer` v4.x if you require old browser support.")}function typedArraySupport(){try{var e=new Uint8Array(1);var r={foo:function(){return 42}};Object.setPrototypeOf(r,Uint8Array.prototype);Object.setPrototypeOf(e,r);return e.foo()===42}catch(e){return false}}Object.defineProperty(Buffer.prototype,"parent",{enumerable:true,get:function(){if(!Buffer.isBuffer(this))return undefined;return this.buffer}});Object.defineProperty(Buffer.prototype,"offset",{enumerable:true,get:function(){if(!Buffer.isBuffer(this))return undefined;return this.byteOffset}});function createBuffer(e){if(e>o){throw new RangeError('The value "'+e+'" is invalid for option "size"')}var r=new Uint8Array(e);Object.setPrototypeOf(r,Buffer.prototype);return r}function Buffer(e,r,t){if(typeof e==="number"){if(typeof r==="string"){throw new TypeError('The "string" argument must be of type string. Received type number')}return allocUnsafe(e)}return from(e,r,t)}Buffer.poolSize=8192;function from(e,r,t){if(typeof e==="string"){return fromString(e,r)}if(ArrayBuffer.isView(e)){return fromArrayLike(e)}if(e==null){throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, "+"or Array-like Object. Received type "+typeof e)}if(isInstance(e,ArrayBuffer)||e&&isInstance(e.buffer,ArrayBuffer)){return fromArrayBuffer(e,r,t)}if(typeof SharedArrayBuffer!=="undefined"&&(isInstance(e,SharedArrayBuffer)||e&&isInstance(e.buffer,SharedArrayBuffer))){return fromArrayBuffer(e,r,t)}if(typeof e==="number"){throw new TypeError('The "value" argument must not be of type number. Received type number')}var f=e.valueOf&&e.valueOf();if(f!=null&&f!==e){return Buffer.from(f,r,t)}var n=fromObject(e);if(n)return n;if(typeof Symbol!=="undefined"&&Symbol.toPrimitive!=null&&typeof e[Symbol.toPrimitive]==="function"){return Buffer.from(e[Symbol.toPrimitive]("string"),r,t)}throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, "+"or Array-like Object. Received type "+typeof e)}Buffer.from=function(e,r,t){return from(e,r,t)};Object.setPrototypeOf(Buffer.prototype,Uint8Array.prototype);Object.setPrototypeOf(Buffer,Uint8Array);function assertSize(e){if(typeof e!=="number"){throw new TypeError('"size" argument must be of type number')}else if(e<0){throw new RangeError('The value "'+e+'" is invalid for option "size"')}}function alloc(e,r,t){assertSize(e);if(e<=0){return createBuffer(e)}if(r!==undefined){return typeof t==="string"?createBuffer(e).fill(r,t):createBuffer(e).fill(r)}return createBuffer(e)}Buffer.alloc=function(e,r,t){return alloc(e,r,t)};function allocUnsafe(e){assertSize(e);return createBuffer(e<0?0:checked(e)|0)}Buffer.allocUnsafe=function(e){return allocUnsafe(e)};Buffer.allocUnsafeSlow=function(e){return allocUnsafe(e)};function fromString(e,r){if(typeof r!=="string"||r===""){r="utf8"}if(!Buffer.isEncoding(r)){throw new TypeError("Unknown encoding: "+r)}var t=byteLength(e,r)|0;var f=createBuffer(t);var n=f.write(e,r);if(n!==t){f=f.slice(0,n)}return f}function fromArrayLike(e){var r=e.length<0?0:checked(e.length)|0;var t=createBuffer(r);for(var f=0;f=o){throw new RangeError("Attempt to allocate Buffer larger than maximum "+"size: 0x"+o.toString(16)+" bytes")}return e|0}function SlowBuffer(e){if(+e!=e){e=0}return Buffer.alloc(+e)}Buffer.isBuffer=function isBuffer(e){return e!=null&&e._isBuffer===true&&e!==Buffer.prototype};Buffer.compare=function compare(e,r){if(isInstance(e,Uint8Array))e=Buffer.from(e,e.offset,e.byteLength);if(isInstance(r,Uint8Array))r=Buffer.from(r,r.offset,r.byteLength);if(!Buffer.isBuffer(e)||!Buffer.isBuffer(r)){throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array')}if(e===r)return 0;var t=e.length;var f=r.length;for(var n=0,i=Math.min(t,f);n2&&arguments[2]===true;if(!f&&t===0)return 0;var n=false;for(;;){switch(r){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return utf8ToBytes(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return base64ToBytes(e).length;default:if(n){return f?-1:utf8ToBytes(e).length}r=(""+r).toLowerCase();n=true}}}Buffer.byteLength=byteLength;function slowToString(e,r,t){var f=false;if(r===undefined||r<0){r=0}if(r>this.length){return""}if(t===undefined||t>this.length){t=this.length}if(t<=0){return""}t>>>=0;r>>>=0;if(t<=r){return""}if(!e)e="utf8";while(true){switch(e){case"hex":return hexSlice(this,r,t);case"utf8":case"utf-8":return utf8Slice(this,r,t);case"ascii":return asciiSlice(this,r,t);case"latin1":case"binary":return latin1Slice(this,r,t);case"base64":return base64Slice(this,r,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return utf16leSlice(this,r,t);default:if(f)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase();f=true}}}Buffer.prototype._isBuffer=true;function swap(e,r,t){var f=e[r];e[r]=e[t];e[t]=f}Buffer.prototype.swap16=function swap16(){var e=this.length;if(e%2!==0){throw new RangeError("Buffer size must be a multiple of 16-bits")}for(var r=0;rt)e+=" ... ";return""};if(i){Buffer.prototype[i]=Buffer.prototype.inspect}Buffer.prototype.compare=function compare(e,r,t,f,n){if(isInstance(e,Uint8Array)){e=Buffer.from(e,e.offset,e.byteLength)}if(!Buffer.isBuffer(e)){throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. '+"Received type "+typeof e)}if(r===undefined){r=0}if(t===undefined){t=e?e.length:0}if(f===undefined){f=0}if(n===undefined){n=this.length}if(r<0||t>e.length||f<0||n>this.length){throw new RangeError("out of range index")}if(f>=n&&r>=t){return 0}if(f>=n){return-1}if(r>=t){return 1}r>>>=0;t>>>=0;f>>>=0;n>>>=0;if(this===e)return 0;var i=n-f;var o=t-r;var u=Math.min(i,o);var a=this.slice(f,n);var s=e.slice(r,t);for(var h=0;h2147483647){t=2147483647}else if(t<-2147483648){t=-2147483648}t=+t;if(numberIsNaN(t)){t=n?0:e.length-1}if(t<0)t=e.length+t;if(t>=e.length){if(n)return-1;else t=e.length-1}else if(t<0){if(n)t=0;else return-1}if(typeof r==="string"){r=Buffer.from(r,f)}if(Buffer.isBuffer(r)){if(r.length===0){return-1}return arrayIndexOf(e,r,t,f,n)}else if(typeof r==="number"){r=r&255;if(typeof Uint8Array.prototype.indexOf==="function"){if(n){return Uint8Array.prototype.indexOf.call(e,r,t)}else{return Uint8Array.prototype.lastIndexOf.call(e,r,t)}}return arrayIndexOf(e,[r],t,f,n)}throw new TypeError("val must be string, number or Buffer")}function arrayIndexOf(e,r,t,f,n){var i=1;var o=e.length;var u=r.length;if(f!==undefined){f=String(f).toLowerCase();if(f==="ucs2"||f==="ucs-2"||f==="utf16le"||f==="utf-16le"){if(e.length<2||r.length<2){return-1}i=2;o/=2;u/=2;t/=2}}function read(e,r){if(i===1){return e[r]}else{return e.readUInt16BE(r*i)}}var a;if(n){var s=-1;for(a=t;ao)t=o-u;for(a=t;a>=0;a--){var h=true;for(var c=0;cn){f=n}}var i=r.length;if(f>i/2){f=i/2}for(var o=0;o>>0;if(isFinite(t)){t=t>>>0;if(f===undefined)f="utf8"}else{f=t;t=undefined}}else{throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported")}var n=this.length-r;if(t===undefined||t>n)t=n;if(e.length>0&&(t<0||r<0)||r>this.length){throw new RangeError("Attempt to write outside buffer bounds")}if(!f)f="utf8";var i=false;for(;;){switch(f){case"hex":return hexWrite(this,e,r,t);case"utf8":case"utf-8":return utf8Write(this,e,r,t);case"ascii":return asciiWrite(this,e,r,t);case"latin1":case"binary":return latin1Write(this,e,r,t);case"base64":return base64Write(this,e,r,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ucs2Write(this,e,r,t);default:if(i)throw new TypeError("Unknown encoding: "+f);f=(""+f).toLowerCase();i=true}}};Buffer.prototype.toJSON=function toJSON(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function base64Slice(e,r,t){if(r===0&&t===e.length){return f.fromByteArray(e)}else{return f.fromByteArray(e.slice(r,t))}}function utf8Slice(e,r,t){t=Math.min(e.length,t);var f=[];var n=r;while(n239?4:i>223?3:i>191?2:1;if(n+u<=t){var a,s,h,c;switch(u){case 1:if(i<128){o=i}break;case 2:a=e[n+1];if((a&192)===128){c=(i&31)<<6|a&63;if(c>127){o=c}}break;case 3:a=e[n+1];s=e[n+2];if((a&192)===128&&(s&192)===128){c=(i&15)<<12|(a&63)<<6|s&63;if(c>2047&&(c<55296||c>57343)){o=c}}break;case 4:a=e[n+1];s=e[n+2];h=e[n+3];if((a&192)===128&&(s&192)===128&&(h&192)===128){c=(i&15)<<18|(a&63)<<12|(s&63)<<6|h&63;if(c>65535&&c<1114112){o=c}}}}if(o===null){o=65533;u=1}else if(o>65535){o-=65536;f.push(o>>>10&1023|55296);o=56320|o&1023}f.push(o);n+=u}return decodeCodePointsArray(f)}var u=4096;function decodeCodePointsArray(e){var r=e.length;if(r<=u){return String.fromCharCode.apply(String,e)}var t="";var f=0;while(ff)t=f;var n="";for(var i=r;it){e=t}if(r<0){r+=t;if(r<0)r=0}else if(r>t){r=t}if(rt)throw new RangeError("Trying to access beyond buffer length")}Buffer.prototype.readUIntLE=function readUIntLE(e,r,t){e=e>>>0;r=r>>>0;if(!t)checkOffset(e,r,this.length);var f=this[e];var n=1;var i=0;while(++i>>0;r=r>>>0;if(!t){checkOffset(e,r,this.length)}var f=this[e+--r];var n=1;while(r>0&&(n*=256)){f+=this[e+--r]*n}return f};Buffer.prototype.readUInt8=function readUInt8(e,r){e=e>>>0;if(!r)checkOffset(e,1,this.length);return this[e]};Buffer.prototype.readUInt16LE=function readUInt16LE(e,r){e=e>>>0;if(!r)checkOffset(e,2,this.length);return this[e]|this[e+1]<<8};Buffer.prototype.readUInt16BE=function readUInt16BE(e,r){e=e>>>0;if(!r)checkOffset(e,2,this.length);return this[e]<<8|this[e+1]};Buffer.prototype.readUInt32LE=function readUInt32LE(e,r){e=e>>>0;if(!r)checkOffset(e,4,this.length);return(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};Buffer.prototype.readUInt32BE=function readUInt32BE(e,r){e=e>>>0;if(!r)checkOffset(e,4,this.length);return this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};Buffer.prototype.readIntLE=function readIntLE(e,r,t){e=e>>>0;r=r>>>0;if(!t)checkOffset(e,r,this.length);var f=this[e];var n=1;var i=0;while(++i=n)f-=Math.pow(2,8*r);return f};Buffer.prototype.readIntBE=function readIntBE(e,r,t){e=e>>>0;r=r>>>0;if(!t)checkOffset(e,r,this.length);var f=r;var n=1;var i=this[e+--f];while(f>0&&(n*=256)){i+=this[e+--f]*n}n*=128;if(i>=n)i-=Math.pow(2,8*r);return i};Buffer.prototype.readInt8=function readInt8(e,r){e=e>>>0;if(!r)checkOffset(e,1,this.length);if(!(this[e]&128))return this[e];return(255-this[e]+1)*-1};Buffer.prototype.readInt16LE=function readInt16LE(e,r){e=e>>>0;if(!r)checkOffset(e,2,this.length);var t=this[e]|this[e+1]<<8;return t&32768?t|4294901760:t};Buffer.prototype.readInt16BE=function readInt16BE(e,r){e=e>>>0;if(!r)checkOffset(e,2,this.length);var t=this[e+1]|this[e]<<8;return t&32768?t|4294901760:t};Buffer.prototype.readInt32LE=function readInt32LE(e,r){e=e>>>0;if(!r)checkOffset(e,4,this.length);return this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};Buffer.prototype.readInt32BE=function readInt32BE(e,r){e=e>>>0;if(!r)checkOffset(e,4,this.length);return this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};Buffer.prototype.readFloatLE=function readFloatLE(e,r){e=e>>>0;if(!r)checkOffset(e,4,this.length);return n.read(this,e,true,23,4)};Buffer.prototype.readFloatBE=function readFloatBE(e,r){e=e>>>0;if(!r)checkOffset(e,4,this.length);return n.read(this,e,false,23,4)};Buffer.prototype.readDoubleLE=function readDoubleLE(e,r){e=e>>>0;if(!r)checkOffset(e,8,this.length);return n.read(this,e,true,52,8)};Buffer.prototype.readDoubleBE=function readDoubleBE(e,r){e=e>>>0;if(!r)checkOffset(e,8,this.length);return n.read(this,e,false,52,8)};function checkInt(e,r,t,f,n,i){if(!Buffer.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>n||re.length)throw new RangeError("Index out of range")}Buffer.prototype.writeUIntLE=function writeUIntLE(e,r,t,f){e=+e;r=r>>>0;t=t>>>0;if(!f){var n=Math.pow(2,8*t)-1;checkInt(this,e,r,t,n,0)}var i=1;var o=0;this[r]=e&255;while(++o>>0;t=t>>>0;if(!f){var n=Math.pow(2,8*t)-1;checkInt(this,e,r,t,n,0)}var i=t-1;var o=1;this[r+i]=e&255;while(--i>=0&&(o*=256)){this[r+i]=e/o&255}return r+t};Buffer.prototype.writeUInt8=function writeUInt8(e,r,t){e=+e;r=r>>>0;if(!t)checkInt(this,e,r,1,255,0);this[r]=e&255;return r+1};Buffer.prototype.writeUInt16LE=function writeUInt16LE(e,r,t){e=+e;r=r>>>0;if(!t)checkInt(this,e,r,2,65535,0);this[r]=e&255;this[r+1]=e>>>8;return r+2};Buffer.prototype.writeUInt16BE=function writeUInt16BE(e,r,t){e=+e;r=r>>>0;if(!t)checkInt(this,e,r,2,65535,0);this[r]=e>>>8;this[r+1]=e&255;return r+2};Buffer.prototype.writeUInt32LE=function writeUInt32LE(e,r,t){e=+e;r=r>>>0;if(!t)checkInt(this,e,r,4,4294967295,0);this[r+3]=e>>>24;this[r+2]=e>>>16;this[r+1]=e>>>8;this[r]=e&255;return r+4};Buffer.prototype.writeUInt32BE=function writeUInt32BE(e,r,t){e=+e;r=r>>>0;if(!t)checkInt(this,e,r,4,4294967295,0);this[r]=e>>>24;this[r+1]=e>>>16;this[r+2]=e>>>8;this[r+3]=e&255;return r+4};Buffer.prototype.writeIntLE=function writeIntLE(e,r,t,f){e=+e;r=r>>>0;if(!f){var n=Math.pow(2,8*t-1);checkInt(this,e,r,t,n-1,-n)}var i=0;var o=1;var u=0;this[r]=e&255;while(++i>0)-u&255}return r+t};Buffer.prototype.writeIntBE=function writeIntBE(e,r,t,f){e=+e;r=r>>>0;if(!f){var n=Math.pow(2,8*t-1);checkInt(this,e,r,t,n-1,-n)}var i=t-1;var o=1;var u=0;this[r+i]=e&255;while(--i>=0&&(o*=256)){if(e<0&&u===0&&this[r+i+1]!==0){u=1}this[r+i]=(e/o>>0)-u&255}return r+t};Buffer.prototype.writeInt8=function writeInt8(e,r,t){e=+e;r=r>>>0;if(!t)checkInt(this,e,r,1,127,-128);if(e<0)e=255+e+1;this[r]=e&255;return r+1};Buffer.prototype.writeInt16LE=function writeInt16LE(e,r,t){e=+e;r=r>>>0;if(!t)checkInt(this,e,r,2,32767,-32768);this[r]=e&255;this[r+1]=e>>>8;return r+2};Buffer.prototype.writeInt16BE=function writeInt16BE(e,r,t){e=+e;r=r>>>0;if(!t)checkInt(this,e,r,2,32767,-32768);this[r]=e>>>8;this[r+1]=e&255;return r+2};Buffer.prototype.writeInt32LE=function writeInt32LE(e,r,t){e=+e;r=r>>>0;if(!t)checkInt(this,e,r,4,2147483647,-2147483648);this[r]=e&255;this[r+1]=e>>>8;this[r+2]=e>>>16;this[r+3]=e>>>24;return r+4};Buffer.prototype.writeInt32BE=function writeInt32BE(e,r,t){e=+e;r=r>>>0;if(!t)checkInt(this,e,r,4,2147483647,-2147483648);if(e<0)e=4294967295+e+1;this[r]=e>>>24;this[r+1]=e>>>16;this[r+2]=e>>>8;this[r+3]=e&255;return r+4};function checkIEEE754(e,r,t,f,n,i){if(t+f>e.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function writeFloat(e,r,t,f,i){r=+r;t=t>>>0;if(!i){checkIEEE754(e,r,t,4,34028234663852886e22,-34028234663852886e22)}n.write(e,r,t,f,23,4);return t+4}Buffer.prototype.writeFloatLE=function writeFloatLE(e,r,t){return writeFloat(this,e,r,true,t)};Buffer.prototype.writeFloatBE=function writeFloatBE(e,r,t){return writeFloat(this,e,r,false,t)};function writeDouble(e,r,t,f,i){r=+r;t=t>>>0;if(!i){checkIEEE754(e,r,t,8,17976931348623157e292,-17976931348623157e292)}n.write(e,r,t,f,52,8);return t+8}Buffer.prototype.writeDoubleLE=function writeDoubleLE(e,r,t){return writeDouble(this,e,r,true,t)};Buffer.prototype.writeDoubleBE=function writeDoubleBE(e,r,t){return writeDouble(this,e,r,false,t)};Buffer.prototype.copy=function copy(e,r,t,f){if(!Buffer.isBuffer(e))throw new TypeError("argument should be a Buffer");if(!t)t=0;if(!f&&f!==0)f=this.length;if(r>=e.length)r=e.length;if(!r)r=0;if(f>0&&f=this.length)throw new RangeError("Index out of range");if(f<0)throw new RangeError("sourceEnd out of bounds");if(f>this.length)f=this.length;if(e.length-r=0;--i){e[i+r]=this[i+t]}}else{Uint8Array.prototype.set.call(e,this.subarray(t,f),r)}return n};Buffer.prototype.fill=function fill(e,r,t,f){if(typeof e==="string"){if(typeof r==="string"){f=r;r=0;t=this.length}else if(typeof t==="string"){f=t;t=this.length}if(f!==undefined&&typeof f!=="string"){throw new TypeError("encoding must be a string")}if(typeof f==="string"&&!Buffer.isEncoding(f)){throw new TypeError("Unknown encoding: "+f)}if(e.length===1){var n=e.charCodeAt(0);if(f==="utf8"&&n<128||f==="latin1"){e=n}}}else if(typeof e==="number"){e=e&255}else if(typeof e==="boolean"){e=Number(e)}if(r<0||this.length>>0;t=t===undefined?this.length:t>>>0;if(!e)e=0;var i;if(typeof e==="number"){for(i=r;i55295&&t<57344){if(!n){if(t>56319){if((r-=3)>-1)i.push(239,191,189);continue}else if(o+1===f){if((r-=3)>-1)i.push(239,191,189);continue}n=t;continue}if(t<56320){if((r-=3)>-1)i.push(239,191,189);n=t;continue}t=(n-55296<<10|t-56320)+65536}else if(n){if((r-=3)>-1)i.push(239,191,189)}n=null;if(t<128){if((r-=1)<0)break;i.push(t)}else if(t<2048){if((r-=2)<0)break;i.push(t>>6|192,t&63|128)}else if(t<65536){if((r-=3)<0)break;i.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((r-=4)<0)break;i.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else{throw new Error("Invalid code point")}}return i}function asciiToBytes(e){var r=[];for(var t=0;t>8;n=t%256;i.push(n);i.push(f)}return i}function base64ToBytes(e){return f.toByteArray(base64clean(e))}function blitBuffer(e,r,t,f){for(var n=0;n=r.length||n>=e.length)break;r[n+t]=e[n]}return n}function isInstance(e,r){return e instanceof r||e!=null&&e.constructor!=null&&e.constructor.name!=null&&e.constructor.name===r.name}function numberIsNaN(e){return e!==e}var s=function(){var e="0123456789abcdef";var r=new Array(256);for(var t=0;t<16;++t){var f=t*16;for(var n=0;n<16;++n){r[f+n]=e[t]+e[n]}}return r}()},783:function(e,r){ +/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */ +r.read=function(e,r,t,f,n){var i,o;var u=n*8-f-1;var a=(1<>1;var h=-7;var c=t?n-1:0;var l=t?-1:1;var p=e[r+c];c+=l;i=p&(1<<-h)-1;p>>=-h;h+=u;for(;h>0;i=i*256+e[r+c],c+=l,h-=8){}o=i&(1<<-h)-1;i>>=-h;h+=f;for(;h>0;o=o*256+e[r+c],c+=l,h-=8){}if(i===0){i=1-s}else if(i===a){return o?NaN:(p?-1:1)*Infinity}else{o=o+Math.pow(2,f);i=i-s}return(p?-1:1)*o*Math.pow(2,i-f)};r.write=function(e,r,t,f,n,i){var o,u,a;var s=i*8-n-1;var h=(1<>1;var l=n===23?Math.pow(2,-24)-Math.pow(2,-77):0;var p=f?0:i-1;var y=f?1:-1;var g=r<0||r===0&&1/r<0?1:0;r=Math.abs(r);if(isNaN(r)||r===Infinity){u=isNaN(r)?1:0;o=h}else{o=Math.floor(Math.log(r)/Math.LN2);if(r*(a=Math.pow(2,-o))<1){o--;a*=2}if(o+c>=1){r+=l/a}else{r+=l*Math.pow(2,1-c)}if(r*a>=2){o++;a/=2}if(o+c>=h){u=0;o=h}else if(o+c>=1){u=(r*a-1)*Math.pow(2,n);o=o+c}else{u=r*Math.pow(2,c-1)*Math.pow(2,n);o=0}}for(;n>=8;e[t+p]=u&255,p+=y,u/=256,n-=8){}o=o<0;e[t+p]=o&255,p+=y,o/=256,s-=8){}e[t+p-y]|=g*128}}};var r={};function __nccwpck_require__(t){var f=r[t];if(f!==undefined){return f.exports}var n=r[t]={exports:{}};var i=true;try{e[t](n,n.exports,__nccwpck_require__);i=false}finally{if(i)delete r[t]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t=__nccwpck_require__(72);module.exports=t})(); + +/***/ }), + +/***/ 9567: +/***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { + +"use strict"; +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "_": function() { return /* binding */ Parser; } +/* harmony export */ }); +class Context { + constructor(importPath, useContextVariables) { + this.code = ""; + this.scopes = [["vars"]]; + this.bitFields = []; + this.tmpVariableCount = 0; + this.references = new Map(); + this.imports = []; + this.reverseImports = new Map(); + this.useContextVariables = false; + this.importPath = importPath; + this.useContextVariables = useContextVariables; + } + generateVariable(name) { + const scopes = [...this.scopes[this.scopes.length - 1]]; + if (name) { + scopes.push(name); + } + return scopes.join("."); + } + generateOption(val) { + switch (typeof val) { + case "number": + return val.toString(); + case "string": + return this.generateVariable(val); + case "function": + return `${this.addImport(val)}.call(${this.generateVariable()}, vars)`; + } + } + generateError(err) { + this.pushCode(`throw new Error(${err});`); + } + generateTmpVariable() { + return "$tmp" + this.tmpVariableCount++; + } + pushCode(code) { + this.code += code + "\n"; + } + pushPath(name) { + if (name) { + this.scopes[this.scopes.length - 1].push(name); + } + } + popPath(name) { + if (name) { + this.scopes[this.scopes.length - 1].pop(); + } + } + pushScope(name) { + this.scopes.push([name]); + } + popScope() { + this.scopes.pop(); + } + addImport(im) { + if (!this.importPath) + return `(${im})`; + let id = this.reverseImports.get(im); + if (!id) { + id = this.imports.push(im) - 1; + this.reverseImports.set(im, id); + } + return `${this.importPath}[${id}]`; + } + addReference(alias) { + if (!this.references.has(alias)) { + this.references.set(alias, { resolved: false, requested: false }); + } + } + markResolved(alias) { + const reference = this.references.get(alias); + if (reference) { + reference.resolved = true; + } + } + markRequested(aliasList) { + aliasList.forEach((alias) => { + const reference = this.references.get(alias); + if (reference) { + reference.requested = true; + } + }); + } + getUnresolvedReferences() { + return Array.from(this.references) + .filter(([_, reference]) => !reference.resolved && !reference.requested) + .map(([alias, _]) => alias); + } +} +const aliasRegistry = new Map(); +const FUNCTION_PREFIX = "___parser_"; +const PRIMITIVE_SIZES = { + uint8: 1, + uint16le: 2, + uint16be: 2, + uint32le: 4, + uint32be: 4, + int8: 1, + int16le: 2, + int16be: 2, + int32le: 4, + int32be: 4, + int64be: 8, + int64le: 8, + uint64be: 8, + uint64le: 8, + floatle: 4, + floatbe: 4, + doublele: 8, + doublebe: 8, +}; +const PRIMITIVE_NAMES = { + uint8: "Uint8", + uint16le: "Uint16", + uint16be: "Uint16", + uint32le: "Uint32", + uint32be: "Uint32", + int8: "Int8", + int16le: "Int16", + int16be: "Int16", + int32le: "Int32", + int32be: "Int32", + int64be: "BigInt64", + int64le: "BigInt64", + uint64be: "BigUint64", + uint64le: "BigUint64", + floatle: "Float32", + floatbe: "Float32", + doublele: "Float64", + doublebe: "Float64", +}; +const PRIMITIVE_LITTLE_ENDIANS = { + uint8: false, + uint16le: true, + uint16be: false, + uint32le: true, + uint32be: false, + int8: false, + int16le: true, + int16be: false, + int32le: true, + int32be: false, + int64be: false, + int64le: true, + uint64be: false, + uint64le: true, + floatle: true, + floatbe: false, + doublele: true, + doublebe: false, +}; +class Parser { + constructor() { + this.varName = ""; + this.type = ""; + this.options = {}; + this.endian = "be"; + this.useContextVariables = false; + } + static start() { + return new Parser(); + } + primitiveGenerateN(type, ctx) { + const typeName = PRIMITIVE_NAMES[type]; + const littleEndian = PRIMITIVE_LITTLE_ENDIANS[type]; + ctx.pushCode(`${ctx.generateVariable(this.varName)} = dataView.get${typeName}(offset, ${littleEndian});`); + ctx.pushCode(`offset += ${PRIMITIVE_SIZES[type]};`); + } + primitiveN(type, varName, options) { + return this.setNextParser(type, varName, options); + } + useThisEndian(type) { + return (type + this.endian.toLowerCase()); + } + uint8(varName, options = {}) { + return this.primitiveN("uint8", varName, options); + } + uint16(varName, options = {}) { + return this.primitiveN(this.useThisEndian("uint16"), varName, options); + } + uint16le(varName, options = {}) { + return this.primitiveN("uint16le", varName, options); + } + uint16be(varName, options = {}) { + return this.primitiveN("uint16be", varName, options); + } + uint32(varName, options = {}) { + return this.primitiveN(this.useThisEndian("uint32"), varName, options); + } + uint32le(varName, options = {}) { + return this.primitiveN("uint32le", varName, options); + } + uint32be(varName, options = {}) { + return this.primitiveN("uint32be", varName, options); + } + int8(varName, options = {}) { + return this.primitiveN("int8", varName, options); + } + int16(varName, options = {}) { + return this.primitiveN(this.useThisEndian("int16"), varName, options); + } + int16le(varName, options = {}) { + return this.primitiveN("int16le", varName, options); + } + int16be(varName, options = {}) { + return this.primitiveN("int16be", varName, options); + } + int32(varName, options = {}) { + return this.primitiveN(this.useThisEndian("int32"), varName, options); + } + int32le(varName, options = {}) { + return this.primitiveN("int32le", varName, options); + } + int32be(varName, options = {}) { + return this.primitiveN("int32be", varName, options); + } + bigIntVersionCheck() { + if (!DataView.prototype.getBigInt64) + throw new Error("BigInt64 is unsupported on this runtime"); + } + int64(varName, options = {}) { + this.bigIntVersionCheck(); + return this.primitiveN(this.useThisEndian("int64"), varName, options); + } + int64be(varName, options = {}) { + this.bigIntVersionCheck(); + return this.primitiveN("int64be", varName, options); + } + int64le(varName, options = {}) { + this.bigIntVersionCheck(); + return this.primitiveN("int64le", varName, options); + } + uint64(varName, options = {}) { + this.bigIntVersionCheck(); + return this.primitiveN(this.useThisEndian("uint64"), varName, options); + } + uint64be(varName, options = {}) { + this.bigIntVersionCheck(); + return this.primitiveN("uint64be", varName, options); + } + uint64le(varName, options = {}) { + this.bigIntVersionCheck(); + return this.primitiveN("uint64le", varName, options); + } + floatle(varName, options = {}) { + return this.primitiveN("floatle", varName, options); + } + floatbe(varName, options = {}) { + return this.primitiveN("floatbe", varName, options); + } + doublele(varName, options = {}) { + return this.primitiveN("doublele", varName, options); + } + doublebe(varName, options = {}) { + return this.primitiveN("doublebe", varName, options); + } + bitN(size, varName, options) { + options.length = size; + return this.setNextParser("bit", varName, options); + } + bit1(varName, options = {}) { + return this.bitN(1, varName, options); + } + bit2(varName, options = {}) { + return this.bitN(2, varName, options); + } + bit3(varName, options = {}) { + return this.bitN(3, varName, options); + } + bit4(varName, options = {}) { + return this.bitN(4, varName, options); + } + bit5(varName, options = {}) { + return this.bitN(5, varName, options); + } + bit6(varName, options = {}) { + return this.bitN(6, varName, options); + } + bit7(varName, options = {}) { + return this.bitN(7, varName, options); + } + bit8(varName, options = {}) { + return this.bitN(8, varName, options); + } + bit9(varName, options = {}) { + return this.bitN(9, varName, options); + } + bit10(varName, options = {}) { + return this.bitN(10, varName, options); + } + bit11(varName, options = {}) { + return this.bitN(11, varName, options); + } + bit12(varName, options = {}) { + return this.bitN(12, varName, options); + } + bit13(varName, options = {}) { + return this.bitN(13, varName, options); + } + bit14(varName, options = {}) { + return this.bitN(14, varName, options); + } + bit15(varName, options = {}) { + return this.bitN(15, varName, options); + } + bit16(varName, options = {}) { + return this.bitN(16, varName, options); + } + bit17(varName, options = {}) { + return this.bitN(17, varName, options); + } + bit18(varName, options = {}) { + return this.bitN(18, varName, options); + } + bit19(varName, options = {}) { + return this.bitN(19, varName, options); + } + bit20(varName, options = {}) { + return this.bitN(20, varName, options); + } + bit21(varName, options = {}) { + return this.bitN(21, varName, options); + } + bit22(varName, options = {}) { + return this.bitN(22, varName, options); + } + bit23(varName, options = {}) { + return this.bitN(23, varName, options); + } + bit24(varName, options = {}) { + return this.bitN(24, varName, options); + } + bit25(varName, options = {}) { + return this.bitN(25, varName, options); + } + bit26(varName, options = {}) { + return this.bitN(26, varName, options); + } + bit27(varName, options = {}) { + return this.bitN(27, varName, options); + } + bit28(varName, options = {}) { + return this.bitN(28, varName, options); + } + bit29(varName, options = {}) { + return this.bitN(29, varName, options); + } + bit30(varName, options = {}) { + return this.bitN(30, varName, options); + } + bit31(varName, options = {}) { + return this.bitN(31, varName, options); + } + bit32(varName, options = {}) { + return this.bitN(32, varName, options); + } + namely(alias) { + aliasRegistry.set(alias, this); + this.alias = alias; + return this; + } + skip(length, options = {}) { + return this.seek(length, options); + } + seek(relOffset, options = {}) { + if (options.assert) { + throw new Error("assert option on seek is not allowed."); + } + return this.setNextParser("seek", "", { length: relOffset }); + } + string(varName, options) { + if (!options.zeroTerminated && !options.length && !options.greedy) { + throw new Error("One of length, zeroTerminated, or greedy must be defined for string."); + } + if ((options.zeroTerminated || options.length) && options.greedy) { + throw new Error("greedy is mutually exclusive with length and zeroTerminated for string."); + } + if (options.stripNull && !(options.length || options.greedy)) { + throw new Error("length or greedy must be defined if stripNull is enabled."); + } + options.encoding = options.encoding || "utf8"; + return this.setNextParser("string", varName, options); + } + buffer(varName, options) { + if (!options.length && !options.readUntil) { + throw new Error("length or readUntil must be defined for buffer."); + } + return this.setNextParser("buffer", varName, options); + } + wrapped(varName, options) { + if (typeof options !== "object" && typeof varName === "object") { + options = varName; + varName = ""; + } + if (!options || !options.wrapper || !options.type) { + throw new Error("Both wrapper and type must be defined for wrapped."); + } + if (!options.length && !options.readUntil) { + throw new Error("length or readUntil must be defined for wrapped."); + } + return this.setNextParser("wrapper", varName, options); + } + array(varName, options) { + if (!options.readUntil && !options.length && !options.lengthInBytes) { + throw new Error("One of readUntil, length and lengthInBytes must be defined for array."); + } + if (!options.type) { + throw new Error("type is required for array."); + } + if (typeof options.type === "string" && + !aliasRegistry.has(options.type) && + !(options.type in PRIMITIVE_SIZES)) { + throw new Error(`Array element type "${options.type}" is unkown.`); + } + return this.setNextParser("array", varName, options); + } + choice(varName, options) { + if (typeof options !== "object" && typeof varName === "object") { + options = varName; + varName = ""; + } + if (!options) { + throw new Error("tag and choices are are required for choice."); + } + if (!options.tag) { + throw new Error("tag is requird for choice."); + } + if (!options.choices) { + throw new Error("choices is required for choice."); + } + for (const keyString in options.choices) { + const key = parseInt(keyString, 10); + const value = options.choices[key]; + if (isNaN(key)) { + throw new Error(`Choice key "${keyString}" is not a number.`); + } + if (typeof value === "string" && + !aliasRegistry.has(value) && + !(value in PRIMITIVE_SIZES)) { + throw new Error(`Choice type "${value}" is unkown.`); + } + } + return this.setNextParser("choice", varName, options); + } + nest(varName, options) { + if (typeof options !== "object" && typeof varName === "object") { + options = varName; + varName = ""; + } + if (!options || !options.type) { + throw new Error("type is required for nest."); + } + if (!(options.type instanceof Parser) && !aliasRegistry.has(options.type)) { + throw new Error("type must be a known parser name or a Parser object."); + } + if (!(options.type instanceof Parser) && !varName) { + throw new Error("type must be a Parser object if the variable name is omitted."); + } + return this.setNextParser("nest", varName, options); + } + pointer(varName, options) { + if (!options.offset) { + throw new Error("offset is required for pointer."); + } + if (!options.type) { + throw new Error("type is required for pointer."); + } + if (typeof options.type === "string" && + !(options.type in PRIMITIVE_SIZES) && + !aliasRegistry.has(options.type)) { + throw new Error(`Pointer type "${options.type}" is unkown.`); + } + return this.setNextParser("pointer", varName, options); + } + saveOffset(varName, options = {}) { + return this.setNextParser("saveOffset", varName, options); + } + endianness(endianness) { + switch (endianness.toLowerCase()) { + case "little": + this.endian = "le"; + break; + case "big": + this.endian = "be"; + break; + default: + throw new Error('endianness must be one of "little" or "big"'); + } + return this; + } + endianess(endianess) { + return this.endianness(endianess); + } + useContextVars(useContextVariables = true) { + this.useContextVariables = useContextVariables; + return this; + } + create(constructorFn) { + if (!(constructorFn instanceof Function)) { + throw new Error("Constructor must be a Function object."); + } + this.constructorFn = constructorFn; + return this; + } + getContext(importPath) { + const ctx = new Context(importPath, this.useContextVariables); + ctx.pushCode("var dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.length);"); + if (!this.alias) { + this.addRawCode(ctx); + } + else { + this.addAliasedCode(ctx); + ctx.pushCode(`return ${FUNCTION_PREFIX + this.alias}(0).result;`); + } + return ctx; + } + getCode() { + const importPath = "imports"; + return this.getContext(importPath).code; + } + addRawCode(ctx) { + ctx.pushCode("var offset = 0;"); + ctx.pushCode(`var vars = ${this.constructorFn ? "new constructorFn()" : "{}"};`); + ctx.pushCode("vars.$parent = null;"); + ctx.pushCode("vars.$root = vars;"); + this.generate(ctx); + this.resolveReferences(ctx); + ctx.pushCode("delete vars.$parent;"); + ctx.pushCode("delete vars.$root;"); + ctx.pushCode("return vars;"); + } + addAliasedCode(ctx) { + ctx.pushCode(`function ${FUNCTION_PREFIX + this.alias}(offset, context) {`); + ctx.pushCode(`var vars = ${this.constructorFn ? "new constructorFn()" : "{}"};`); + ctx.pushCode("var ctx = Object.assign({$parent: null, $root: vars}, context || {});"); + ctx.pushCode(`vars = Object.assign(vars, ctx);`); + this.generate(ctx); + ctx.markResolved(this.alias); + this.resolveReferences(ctx); + ctx.pushCode("Object.keys(ctx).forEach(function (item) { delete vars[item]; });"); + ctx.pushCode("return { offset: offset, result: vars };"); + ctx.pushCode("}"); + return ctx; + } + resolveReferences(ctx) { + const references = ctx.getUnresolvedReferences(); + ctx.markRequested(references); + references.forEach((alias) => { + var _a; + (_a = aliasRegistry.get(alias)) === null || _a === void 0 ? void 0 : _a.addAliasedCode(ctx); + }); + } + compile() { + const importPath = "imports"; + const ctx = this.getContext(importPath); + this.compiled = new Function(importPath, "TextDecoder", `return function (buffer, constructorFn) { ${ctx.code} };`)(ctx.imports, TextDecoder); + } + sizeOf() { + let size = NaN; + if (Object.keys(PRIMITIVE_SIZES).indexOf(this.type) >= 0) { + size = PRIMITIVE_SIZES[this.type]; + // if this is a fixed length string + } + else if (this.type === "string" && + typeof this.options.length === "number") { + size = this.options.length; + // if this is a fixed length buffer + } + else if (this.type === "buffer" && + typeof this.options.length === "number") { + size = this.options.length; + // if this is a fixed length array + } + else if (this.type === "array" && + typeof this.options.length === "number") { + let elementSize = NaN; + if (typeof this.options.type === "string") { + elementSize = PRIMITIVE_SIZES[this.options.type]; + } + else if (this.options.type instanceof Parser) { + elementSize = this.options.type.sizeOf(); + } + size = this.options.length * elementSize; + // if this a skip + } + else if (this.type === "seek") { + size = this.options.length; + // if this is a nested parser + } + else if (this.type === "nest") { + size = this.options.type.sizeOf(); + } + else if (!this.type) { + size = 0; + } + if (this.next) { + size += this.next.sizeOf(); + } + return size; + } + // Follow the parser chain till the root and start parsing from there + parse(buffer) { + if (!this.compiled) { + this.compile(); + } + return this.compiled(buffer, this.constructorFn); + } + setNextParser(type, varName, options) { + const parser = new Parser(); + parser.type = type; + parser.varName = varName; + parser.options = options; + parser.endian = this.endian; + if (this.head) { + this.head.next = parser; + } + else { + this.next = parser; + } + this.head = parser; + return this; + } + // Call code generator for this parser + generate(ctx) { + if (this.type) { + switch (this.type) { + case "uint8": + case "uint16le": + case "uint16be": + case "uint32le": + case "uint32be": + case "int8": + case "int16le": + case "int16be": + case "int32le": + case "int32be": + case "int64be": + case "int64le": + case "uint64be": + case "uint64le": + case "floatle": + case "floatbe": + case "doublele": + case "doublebe": + this.primitiveGenerateN(this.type, ctx); + break; + case "bit": + this.generateBit(ctx); + break; + case "string": + this.generateString(ctx); + break; + case "buffer": + this.generateBuffer(ctx); + break; + case "seek": + this.generateSeek(ctx); + break; + case "nest": + this.generateNest(ctx); + break; + case "array": + this.generateArray(ctx); + break; + case "choice": + this.generateChoice(ctx); + break; + case "pointer": + this.generatePointer(ctx); + break; + case "saveOffset": + this.generateSaveOffset(ctx); + break; + case "wrapper": + this.generateWrapper(ctx); + break; + } + if (this.type !== "bit") + this.generateAssert(ctx); + } + const varName = ctx.generateVariable(this.varName); + if (this.options.formatter && this.type !== "bit") { + this.generateFormatter(ctx, varName, this.options.formatter); + } + return this.generateNext(ctx); + } + generateAssert(ctx) { + if (!this.options.assert) { + return; + } + const varName = ctx.generateVariable(this.varName); + switch (typeof this.options.assert) { + case "function": + { + const func = ctx.addImport(this.options.assert); + ctx.pushCode(`if (!${func}.call(vars, ${varName})) {`); + } + break; + case "number": + ctx.pushCode(`if (${this.options.assert} !== ${varName}) {`); + break; + case "string": + ctx.pushCode(`if (${JSON.stringify(this.options.assert)} !== ${varName}) {`); + break; + default: + throw new Error("assert option must be a string, number or a function."); + } + ctx.generateError(`"Assertion error: ${varName} is " + ${JSON.stringify(this.options.assert.toString())}`); + ctx.pushCode("}"); + } + // Recursively call code generators and append results + generateNext(ctx) { + if (this.next) { + ctx = this.next.generate(ctx); + } + return ctx; + } + generateBit(ctx) { + // TODO find better method to handle nested bit fields + const parser = JSON.parse(JSON.stringify(this)); + parser.options = this.options; + parser.generateAssert = this.generateAssert.bind(this); + parser.generateFormatter = this.generateFormatter.bind(this); + parser.varName = ctx.generateVariable(parser.varName); + ctx.bitFields.push(parser); + if (!this.next || + (this.next && ["bit", "nest"].indexOf(this.next.type) < 0)) { + const val = ctx.generateTmpVariable(); + ctx.pushCode(`var ${val} = 0;`); + const getMaxBits = (from = 0) => { + let sum = 0; + for (let i = from; i < ctx.bitFields.length; i++) { + const length = ctx.bitFields[i].options.length; + if (sum + length > 32) + break; + sum += length; + } + return sum; + }; + const getBytes = (sum) => { + if (sum <= 8) { + ctx.pushCode(`${val} = dataView.getUint8(offset);`); + sum = 8; + } + else if (sum <= 16) { + ctx.pushCode(`${val} = dataView.getUint16(offset);`); + sum = 16; + } + else if (sum <= 24) { + ctx.pushCode(`${val} = (dataView.getUint16(offset) << 8) | dataView.getUint8(offset + 2);`); + sum = 24; + } + else { + ctx.pushCode(`${val} = dataView.getUint32(offset);`); + sum = 32; + } + ctx.pushCode(`offset += ${sum / 8};`); + return sum; + }; + let bitOffset = 0; + const isBigEndian = this.endian === "be"; + let sum = 0; + let rem = 0; + ctx.bitFields.forEach((parser, i) => { + let length = parser.options.length; + if (length > rem) { + if (rem) { + const mask = -1 >>> (32 - rem); + ctx.pushCode(`${parser.varName} = (${val} & 0x${mask.toString(16)}) << ${length - rem};`); + length -= rem; + } + bitOffset = 0; + rem = sum = getBytes(getMaxBits(i) - rem); + } + const offset = isBigEndian ? sum - bitOffset - length : bitOffset; + const mask = -1 >>> (32 - length); + ctx.pushCode(`${parser.varName} ${length < parser.options.length ? "|=" : "="} ${val} >> ${offset} & 0x${mask.toString(16)};`); + // Ensure value is unsigned + if (parser.options.length === 32) { + ctx.pushCode(`${parser.varName} >>>= 0`); + } + if (parser.options.assert) { + parser.generateAssert(ctx); + } + if (parser.options.formatter) { + parser.generateFormatter(ctx, parser.varName, parser.options.formatter); + } + bitOffset += length; + rem -= length; + }); + ctx.bitFields = []; + } + } + generateSeek(ctx) { + const length = ctx.generateOption(this.options.length); + ctx.pushCode(`offset += ${length};`); + } + generateString(ctx) { + const name = ctx.generateVariable(this.varName); + const start = ctx.generateTmpVariable(); + const encoding = this.options.encoding; + const isHex = encoding.toLowerCase() === "hex"; + const toHex = 'b => b.toString(16).padStart(2, "0")'; + if (this.options.length && this.options.zeroTerminated) { + const len = this.options.length; + ctx.pushCode(`var ${start} = offset;`); + ctx.pushCode(`while(dataView.getUint8(offset++) !== 0 && offset - ${start} < ${len});`); + const end = `offset - ${start} < ${len} ? offset - 1 : offset`; + ctx.pushCode(isHex + ? `${name} = Array.from(buffer.subarray(${start}, ${end}), ${toHex}).join('');` + : `${name} = new TextDecoder('${encoding}').decode(buffer.subarray(${start}, ${end}));`); + } + else if (this.options.length) { + const len = ctx.generateOption(this.options.length); + ctx.pushCode(isHex + ? `${name} = Array.from(buffer.subarray(offset, offset + ${len}), ${toHex}).join('');` + : `${name} = new TextDecoder('${encoding}').decode(buffer.subarray(offset, offset + ${len}));`); + ctx.pushCode(`offset += ${len};`); + } + else if (this.options.zeroTerminated) { + ctx.pushCode(`var ${start} = offset;`); + ctx.pushCode("while(dataView.getUint8(offset++) !== 0);"); + ctx.pushCode(isHex + ? `${name} = Array.from(buffer.subarray(${start}, offset - 1), ${toHex}).join('');` + : `${name} = new TextDecoder('${encoding}').decode(buffer.subarray(${start}, offset - 1));`); + } + else if (this.options.greedy) { + ctx.pushCode(`var ${start} = offset;`); + ctx.pushCode("while(buffer.length > offset++);"); + ctx.pushCode(isHex + ? `${name} = Array.from(buffer.subarray(${start}, offset), ${toHex}).join('');` + : `${name} = new TextDecoder('${encoding}').decode(buffer.subarray(${start}, offset));`); + } + if (this.options.stripNull) { + ctx.pushCode(`${name} = ${name}.replace(/\\x00+$/g, '')`); + } + } + generateBuffer(ctx) { + const varName = ctx.generateVariable(this.varName); + if (typeof this.options.readUntil === "function") { + const pred = this.options.readUntil; + const start = ctx.generateTmpVariable(); + const cur = ctx.generateTmpVariable(); + ctx.pushCode(`var ${start} = offset;`); + ctx.pushCode(`var ${cur} = 0;`); + ctx.pushCode(`while (offset < buffer.length) {`); + ctx.pushCode(`${cur} = dataView.getUint8(offset);`); + const func = ctx.addImport(pred); + ctx.pushCode(`if (${func}.call(${ctx.generateVariable()}, ${cur}, buffer.subarray(offset))) break;`); + ctx.pushCode(`offset += 1;`); + ctx.pushCode(`}`); + ctx.pushCode(`${varName} = buffer.subarray(${start}, offset);`); + } + else if (this.options.readUntil === "eof") { + ctx.pushCode(`${varName} = buffer.subarray(offset);`); + } + else { + const len = ctx.generateOption(this.options.length); + ctx.pushCode(`${varName} = buffer.subarray(offset, offset + ${len});`); + ctx.pushCode(`offset += ${len};`); + } + if (this.options.clone) { + ctx.pushCode(`${varName} = buffer.constructor.from(${varName});`); + } + } + generateArray(ctx) { + const length = ctx.generateOption(this.options.length); + const lengthInBytes = ctx.generateOption(this.options.lengthInBytes); + const type = this.options.type; + const counter = ctx.generateTmpVariable(); + const lhs = ctx.generateVariable(this.varName); + const item = ctx.generateTmpVariable(); + const key = this.options.key; + const isHash = typeof key === "string"; + if (isHash) { + ctx.pushCode(`${lhs} = {};`); + } + else { + ctx.pushCode(`${lhs} = [];`); + } + if (typeof this.options.readUntil === "function") { + ctx.pushCode("do {"); + } + else if (this.options.readUntil === "eof") { + ctx.pushCode(`for (var ${counter} = 0; offset < buffer.length; ${counter}++) {`); + } + else if (lengthInBytes !== undefined) { + ctx.pushCode(`for (var ${counter} = offset + ${lengthInBytes}; offset < ${counter}; ) {`); + } + else { + ctx.pushCode(`for (var ${counter} = ${length}; ${counter} > 0; ${counter}--) {`); + } + if (typeof type === "string") { + if (!aliasRegistry.get(type)) { + const typeName = PRIMITIVE_NAMES[type]; + const littleEndian = PRIMITIVE_LITTLE_ENDIANS[type]; + ctx.pushCode(`var ${item} = dataView.get${typeName}(offset, ${littleEndian});`); + ctx.pushCode(`offset += ${PRIMITIVE_SIZES[type]};`); + } + else { + const tempVar = ctx.generateTmpVariable(); + ctx.pushCode(`var ${tempVar} = ${FUNCTION_PREFIX + type}(offset, {`); + if (ctx.useContextVariables) { + const parentVar = ctx.generateVariable(); + ctx.pushCode(`$parent: ${parentVar},`); + ctx.pushCode(`$root: ${parentVar}.$root,`); + if (!this.options.readUntil && lengthInBytes === undefined) { + ctx.pushCode(`$index: ${length} - ${counter},`); + } + } + ctx.pushCode(`});`); + ctx.pushCode(`var ${item} = ${tempVar}.result; offset = ${tempVar}.offset;`); + if (type !== this.alias) + ctx.addReference(type); + } + } + else if (type instanceof Parser) { + ctx.pushCode(`var ${item} = {};`); + const parentVar = ctx.generateVariable(); + ctx.pushScope(item); + if (ctx.useContextVariables) { + ctx.pushCode(`${item}.$parent = ${parentVar};`); + ctx.pushCode(`${item}.$root = ${parentVar}.$root;`); + if (!this.options.readUntil && lengthInBytes === undefined) { + ctx.pushCode(`${item}.$index = ${length} - ${counter};`); + } + } + type.generate(ctx); + if (ctx.useContextVariables) { + ctx.pushCode(`delete ${item}.$parent;`); + ctx.pushCode(`delete ${item}.$root;`); + ctx.pushCode(`delete ${item}.$index;`); + } + ctx.popScope(); + } + if (isHash) { + ctx.pushCode(`${lhs}[${item}.${key}] = ${item};`); + } + else { + ctx.pushCode(`${lhs}.push(${item});`); + } + ctx.pushCode("}"); + if (typeof this.options.readUntil === "function") { + const pred = this.options.readUntil; + const func = ctx.addImport(pred); + ctx.pushCode(`while (!${func}.call(${ctx.generateVariable()}, ${item}, buffer.subarray(offset)));`); + } + } + generateChoiceCase(ctx, varName, type) { + if (typeof type === "string") { + const varName = ctx.generateVariable(this.varName); + if (!aliasRegistry.has(type)) { + const typeName = PRIMITIVE_NAMES[type]; + const littleEndian = PRIMITIVE_LITTLE_ENDIANS[type]; + ctx.pushCode(`${varName} = dataView.get${typeName}(offset, ${littleEndian});`); + ctx.pushCode(`offset += ${PRIMITIVE_SIZES[type]}`); + } + else { + const tempVar = ctx.generateTmpVariable(); + ctx.pushCode(`var ${tempVar} = ${FUNCTION_PREFIX + type}(offset, {`); + if (ctx.useContextVariables) { + ctx.pushCode(`$parent: ${varName}.$parent,`); + ctx.pushCode(`$root: ${varName}.$root,`); + } + ctx.pushCode(`});`); + ctx.pushCode(`${varName} = ${tempVar}.result; offset = ${tempVar}.offset;`); + if (type !== this.alias) + ctx.addReference(type); + } + } + else if (type instanceof Parser) { + ctx.pushPath(varName); + type.generate(ctx); + ctx.popPath(varName); + } + } + generateChoice(ctx) { + const tag = ctx.generateOption(this.options.tag); + const nestVar = ctx.generateVariable(this.varName); + if (this.varName) { + ctx.pushCode(`${nestVar} = {};`); + if (ctx.useContextVariables) { + const parentVar = ctx.generateVariable(); + ctx.pushCode(`${nestVar}.$parent = ${parentVar};`); + ctx.pushCode(`${nestVar}.$root = ${parentVar}.$root;`); + } + } + ctx.pushCode(`switch(${tag}) {`); + for (const tagString in this.options.choices) { + const tag = parseInt(tagString, 10); + const type = this.options.choices[tag]; + ctx.pushCode(`case ${tag}:`); + this.generateChoiceCase(ctx, this.varName, type); + ctx.pushCode("break;"); + } + ctx.pushCode("default:"); + if (this.options.defaultChoice) { + this.generateChoiceCase(ctx, this.varName, this.options.defaultChoice); + } + else { + ctx.generateError(`"Met undefined tag value " + ${tag} + " at choice"`); + } + ctx.pushCode("}"); + if (this.varName && ctx.useContextVariables) { + ctx.pushCode(`delete ${nestVar}.$parent;`); + ctx.pushCode(`delete ${nestVar}.$root;`); + } + } + generateNest(ctx) { + const nestVar = ctx.generateVariable(this.varName); + if (this.options.type instanceof Parser) { + if (this.varName) { + ctx.pushCode(`${nestVar} = {};`); + if (ctx.useContextVariables) { + const parentVar = ctx.generateVariable(); + ctx.pushCode(`${nestVar}.$parent = ${parentVar};`); + ctx.pushCode(`${nestVar}.$root = ${parentVar}.$root;`); + } + } + ctx.pushPath(this.varName); + this.options.type.generate(ctx); + ctx.popPath(this.varName); + if (this.varName && ctx.useContextVariables) { + if (ctx.useContextVariables) { + ctx.pushCode(`delete ${nestVar}.$parent;`); + ctx.pushCode(`delete ${nestVar}.$root;`); + } + } + } + else if (aliasRegistry.has(this.options.type)) { + const tempVar = ctx.generateTmpVariable(); + ctx.pushCode(`var ${tempVar} = ${FUNCTION_PREFIX + this.options.type}(offset, {`); + if (ctx.useContextVariables) { + const parentVar = ctx.generateVariable(); + ctx.pushCode(`$parent: ${parentVar},`); + ctx.pushCode(`$root: ${parentVar}.$root,`); + } + ctx.pushCode(`});`); + ctx.pushCode(`${nestVar} = ${tempVar}.result; offset = ${tempVar}.offset;`); + if (this.options.type !== this.alias) { + ctx.addReference(this.options.type); + } + } + } + generateWrapper(ctx) { + const wrapperVar = ctx.generateVariable(this.varName); + const wrappedBuf = ctx.generateTmpVariable(); + if (typeof this.options.readUntil === "function") { + const pred = this.options.readUntil; + const start = ctx.generateTmpVariable(); + const cur = ctx.generateTmpVariable(); + ctx.pushCode(`var ${start} = offset;`); + ctx.pushCode(`var ${cur} = 0;`); + ctx.pushCode(`while (offset < buffer.length) {`); + ctx.pushCode(`${cur} = dataView.getUint8(offset);`); + const func = ctx.addImport(pred); + ctx.pushCode(`if (${func}.call(${ctx.generateVariable()}, ${cur}, buffer.subarray(offset))) break;`); + ctx.pushCode(`offset += 1;`); + ctx.pushCode(`}`); + ctx.pushCode(`${wrappedBuf} = buffer.subarray(${start}, offset);`); + } + else if (this.options.readUntil === "eof") { + ctx.pushCode(`${wrappedBuf} = buffer.subarray(offset);`); + } + else { + const len = ctx.generateOption(this.options.length); + ctx.pushCode(`${wrappedBuf} = buffer.subarray(offset, offset + ${len});`); + ctx.pushCode(`offset += ${len};`); + } + if (this.options.clone) { + ctx.pushCode(`${wrappedBuf} = buffer.constructor.from(${wrappedBuf});`); + } + const tempBuf = ctx.generateTmpVariable(); + const tempOff = ctx.generateTmpVariable(); + const tempView = ctx.generateTmpVariable(); + const func = ctx.addImport(this.options.wrapper); + ctx.pushCode(`${wrappedBuf} = ${func}.call(this, ${wrappedBuf}).subarray(0);`); + ctx.pushCode(`var ${tempBuf} = buffer;`); + ctx.pushCode(`var ${tempOff} = offset;`); + ctx.pushCode(`var ${tempView} = dataView;`); + ctx.pushCode(`buffer = ${wrappedBuf};`); + ctx.pushCode(`offset = 0;`); + ctx.pushCode(`dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.length);`); + if (this.options.type instanceof Parser) { + if (this.varName) { + ctx.pushCode(`${wrapperVar} = {};`); + } + ctx.pushPath(this.varName); + this.options.type.generate(ctx); + ctx.popPath(this.varName); + } + else if (aliasRegistry.has(this.options.type)) { + const tempVar = ctx.generateTmpVariable(); + ctx.pushCode(`var ${tempVar} = ${FUNCTION_PREFIX + this.options.type}(0);`); + ctx.pushCode(`${wrapperVar} = ${tempVar}.result;`); + if (this.options.type !== this.alias) { + ctx.addReference(this.options.type); + } + } + ctx.pushCode(`buffer = ${tempBuf};`); + ctx.pushCode(`dataView = ${tempView};`); + ctx.pushCode(`offset = ${tempOff};`); + } + generateFormatter(ctx, varName, formatter) { + if (typeof formatter === "function") { + const func = ctx.addImport(formatter); + ctx.pushCode(`${varName} = ${func}.call(${ctx.generateVariable()}, ${varName});`); + } + } + generatePointer(ctx) { + const type = this.options.type; + const offset = ctx.generateOption(this.options.offset); + const tempVar = ctx.generateTmpVariable(); + const nestVar = ctx.generateVariable(this.varName); + // Save current offset + ctx.pushCode(`var ${tempVar} = offset;`); + // Move offset + ctx.pushCode(`offset = ${offset};`); + if (this.options.type instanceof Parser) { + ctx.pushCode(`${nestVar} = {};`); + if (ctx.useContextVariables) { + const parentVar = ctx.generateVariable(); + ctx.pushCode(`${nestVar}.$parent = ${parentVar};`); + ctx.pushCode(`${nestVar}.$root = ${parentVar}.$root;`); + } + ctx.pushPath(this.varName); + this.options.type.generate(ctx); + ctx.popPath(this.varName); + if (ctx.useContextVariables) { + ctx.pushCode(`delete ${nestVar}.$parent;`); + ctx.pushCode(`delete ${nestVar}.$root;`); + } + } + else if (aliasRegistry.has(this.options.type)) { + const tempVar = ctx.generateTmpVariable(); + ctx.pushCode(`var ${tempVar} = ${FUNCTION_PREFIX + this.options.type}(offset, {`); + if (ctx.useContextVariables) { + const parentVar = ctx.generateVariable(); + ctx.pushCode(`$parent: ${parentVar},`); + ctx.pushCode(`$root: ${parentVar}.$root,`); + } + ctx.pushCode(`});`); + ctx.pushCode(`${nestVar} = ${tempVar}.result; offset = ${tempVar}.offset;`); + if (this.options.type !== this.alias) { + ctx.addReference(this.options.type); + } + } + else if (Object.keys(PRIMITIVE_SIZES).indexOf(this.options.type) >= 0) { + const typeName = PRIMITIVE_NAMES[type]; + const littleEndian = PRIMITIVE_LITTLE_ENDIANS[type]; + ctx.pushCode(`${nestVar} = dataView.get${typeName}(offset, ${littleEndian});`); + ctx.pushCode(`offset += ${PRIMITIVE_SIZES[type]};`); + } + // Restore offset + ctx.pushCode(`offset = ${tempVar};`); + } + generateSaveOffset(ctx) { + const varName = ctx.generateVariable(this.varName); + ctx.pushCode(`${varName} = offset`); + } +} +//# sourceMappingURL=binary_parser.js.map + +/***/ }) + +}]); \ No newline at end of file diff --git a/crates/swc_ecma_minifier/tests/fixture/next/43208/static/chunks/framework-5ab552f91d1ae590/input.js b/crates/swc_ecma_minifier/tests/fixture/next/43208/static/chunks/framework-5ab552f91d1ae590/input.js new file mode 100644 index 000000000000..05105c3a3b3a --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/next/43208/static/chunks/framework-5ab552f91d1ae590/input.js @@ -0,0 +1,496 @@ +"use strict"; +(self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([[774],{ + +/***/ 4448: +/***/ (function(__unused_webpack_module, exports, __webpack_require__) { + +/** + * @license React + * react-dom.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +/* + Modernizr 3.0.0pre (Custom Build) | MIT +*/ +var aa=__webpack_require__(7294),ca=__webpack_require__(3840);function p(a){for(var b="https://reactjs.org/docs/error-decoder.html?invariant="+a,c=1;cb}return!1}function v(a,b,c,d,e,f,g){this.acceptsBooleans=2===b||3===b||4===b;this.attributeName=d;this.attributeNamespace=e;this.mustUseProperty=c;this.propertyName=a;this.type=b;this.sanitizeURL=f;this.removeEmptyString=g}var z={}; +"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(a){z[a]=new v(a,0,!1,a,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(a){var b=a[0];z[b]=new v(b,1,!1,a[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(a){z[a]=new v(a,2,!1,a.toLowerCase(),null,!1,!1)}); +["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(a){z[a]=new v(a,2,!1,a,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(a){z[a]=new v(a,3,!1,a.toLowerCase(),null,!1,!1)}); +["checked","multiple","muted","selected"].forEach(function(a){z[a]=new v(a,3,!0,a,null,!1,!1)});["capture","download"].forEach(function(a){z[a]=new v(a,4,!1,a,null,!1,!1)});["cols","rows","size","span"].forEach(function(a){z[a]=new v(a,6,!1,a,null,!1,!1)});["rowSpan","start"].forEach(function(a){z[a]=new v(a,5,!1,a.toLowerCase(),null,!1,!1)});var ra=/[\-:]([a-z])/g;function sa(a){return a[1].toUpperCase()} +"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(a){var b=a.replace(ra, +sa);z[b]=new v(b,1,!1,a,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(a){var b=a.replace(ra,sa);z[b]=new v(b,1,!1,a,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(a){var b=a.replace(ra,sa);z[b]=new v(b,1,!1,a,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(a){z[a]=new v(a,1,!1,a.toLowerCase(),null,!1,!1)}); +z.xlinkHref=new v("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(a){z[a]=new v(a,1,!1,a.toLowerCase(),null,!0,!0)}); +function ta(a,b,c,d){var e=z.hasOwnProperty(b)?z[b]:null;if(null!==e?0!==e.type:d||!(2h||e[g]!==f[h]){var k="\n"+e[g].replace(" at new "," at ");a.displayName&&k.includes("")&&(k=k.replace("",a.displayName));return k}while(1<=g&&0<=h)}break}}}finally{Na=!1,Error.prepareStackTrace=c}return(a=a?a.displayName||a.name:"")?Ma(a):""} +function Pa(a){switch(a.tag){case 5:return Ma(a.type);case 16:return Ma("Lazy");case 13:return Ma("Suspense");case 19:return Ma("SuspenseList");case 0:case 2:case 15:return a=Oa(a.type,!1),a;case 11:return a=Oa(a.type.render,!1),a;case 1:return a=Oa(a.type,!0),a;default:return""}} +function Qa(a){if(null==a)return null;if("function"===typeof a)return a.displayName||a.name||null;if("string"===typeof a)return a;switch(a){case ya:return"Fragment";case wa:return"Portal";case Aa:return"Profiler";case za:return"StrictMode";case Ea:return"Suspense";case Fa:return"SuspenseList"}if("object"===typeof a)switch(a.$$typeof){case Ca:return(a.displayName||"Context")+".Consumer";case Ba:return(a._context.displayName||"Context")+".Provider";case Da:var b=a.render;a=a.displayName;a||(a=b.displayName|| +b.name||"",a=""!==a?"ForwardRef("+a+")":"ForwardRef");return a;case Ga:return b=a.displayName||null,null!==b?b:Qa(a.type)||"Memo";case Ha:b=a._payload;a=a._init;try{return Qa(a(b))}catch(c){}}return null} +function Ra(a){var b=a.type;switch(a.tag){case 24:return"Cache";case 9:return(b.displayName||"Context")+".Consumer";case 10:return(b._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return a=b.render,a=a.displayName||a.name||"",b.displayName||(""!==a?"ForwardRef("+a+")":"ForwardRef");case 7:return"Fragment";case 5:return b;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return Qa(b);case 8:return b===za?"StrictMode":"Mode";case 22:return"Offscreen"; +case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if("function"===typeof b)return b.displayName||b.name||null;if("string"===typeof b)return b}return null}function Sa(a){switch(typeof a){case "boolean":case "number":case "string":case "undefined":return a;case "object":return a;default:return""}} +function Ta(a){var b=a.type;return(a=a.nodeName)&&"input"===a.toLowerCase()&&("checkbox"===b||"radio"===b)} +function Ua(a){var b=Ta(a)?"checked":"value",c=Object.getOwnPropertyDescriptor(a.constructor.prototype,b),d=""+a[b];if(!a.hasOwnProperty(b)&&"undefined"!==typeof c&&"function"===typeof c.get&&"function"===typeof c.set){var e=c.get,f=c.set;Object.defineProperty(a,b,{configurable:!0,get:function(){return e.call(this)},set:function(a){d=""+a;f.call(this,a)}});Object.defineProperty(a,b,{enumerable:c.enumerable});return{getValue:function(){return d},setValue:function(a){d=""+a},stopTracking:function(){a._valueTracker= +null;delete a[b]}}}}function Va(a){a._valueTracker||(a._valueTracker=Ua(a))}function Wa(a){if(!a)return!1;var b=a._valueTracker;if(!b)return!0;var c=b.getValue();var d="";a&&(d=Ta(a)?a.checked?"true":"false":a.value);a=d;return a!==c?(b.setValue(a),!0):!1}function Xa(a){a=a||("undefined"!==typeof document?document:void 0);if("undefined"===typeof a)return null;try{return a.activeElement||a.body}catch(b){return a.body}} +function Ya(a,b){var c=b.checked;return A({},b,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:null!=c?c:a._wrapperState.initialChecked})}function Za(a,b){var c=null==b.defaultValue?"":b.defaultValue,d=null!=b.checked?b.checked:b.defaultChecked;c=Sa(null!=b.value?b.value:c);a._wrapperState={initialChecked:d,initialValue:c,controlled:"checkbox"===b.type||"radio"===b.type?null!=b.checked:null!=b.value}}function ab(a,b){b=b.checked;null!=b&&ta(a,"checked",b,!1)} +function bb(a,b){ab(a,b);var c=Sa(b.value),d=b.type;if(null!=c)if("number"===d){if(0===c&&""===a.value||a.value!=c)a.value=""+c}else a.value!==""+c&&(a.value=""+c);else if("submit"===d||"reset"===d){a.removeAttribute("value");return}b.hasOwnProperty("value")?cb(a,b.type,c):b.hasOwnProperty("defaultValue")&&cb(a,b.type,Sa(b.defaultValue));null==b.checked&&null!=b.defaultChecked&&(a.defaultChecked=!!b.defaultChecked)} +function db(a,b,c){if(b.hasOwnProperty("value")||b.hasOwnProperty("defaultValue")){var d=b.type;if(!("submit"!==d&&"reset"!==d||void 0!==b.value&&null!==b.value))return;b=""+a._wrapperState.initialValue;c||b===a.value||(a.value=b);a.defaultValue=b}c=a.name;""!==c&&(a.name="");a.defaultChecked=!!a._wrapperState.initialChecked;""!==c&&(a.name=c)} +function cb(a,b,c){if("number"!==b||Xa(a.ownerDocument)!==a)null==c?a.defaultValue=""+a._wrapperState.initialValue:a.defaultValue!==""+c&&(a.defaultValue=""+c)}var eb=Array.isArray; +function fb(a,b,c,d){a=a.options;if(b){b={};for(var e=0;e"+b.valueOf().toString()+"";for(b=mb.firstChild;a.firstChild;)a.removeChild(a.firstChild);for(;b.firstChild;)a.appendChild(b.firstChild)}}); +function ob(a,b){if(b){var c=a.firstChild;if(c&&c===a.lastChild&&3===c.nodeType){c.nodeValue=b;return}}a.textContent=b} +var pb={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0, +zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},qb=["Webkit","ms","Moz","O"];Object.keys(pb).forEach(function(a){qb.forEach(function(b){b=b+a.charAt(0).toUpperCase()+a.substring(1);pb[b]=pb[a]})});function rb(a,b,c){return null==b||"boolean"===typeof b||""===b?"":c||"number"!==typeof b||0===b||pb.hasOwnProperty(a)&&pb[a]?(""+b).trim():b+"px"} +function sb(a,b){a=a.style;for(var c in b)if(b.hasOwnProperty(c)){var d=0===c.indexOf("--"),e=rb(c,b[c],d);"float"===c&&(c="cssFloat");d?a.setProperty(c,e):a[c]=e}}var tb=A({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}); +function ub(a,b){if(b){if(tb[a]&&(null!=b.children||null!=b.dangerouslySetInnerHTML))throw Error(p(137,a));if(null!=b.dangerouslySetInnerHTML){if(null!=b.children)throw Error(p(60));if("object"!==typeof b.dangerouslySetInnerHTML||!("__html"in b.dangerouslySetInnerHTML))throw Error(p(61));}if(null!=b.style&&"object"!==typeof b.style)throw Error(p(62));}} +function vb(a,b){if(-1===a.indexOf("-"))return"string"===typeof b.is;switch(a){case "annotation-xml":case "color-profile":case "font-face":case "font-face-src":case "font-face-uri":case "font-face-format":case "font-face-name":case "missing-glyph":return!1;default:return!0}}var wb=null;function xb(a){a=a.target||a.srcElement||window;a.correspondingUseElement&&(a=a.correspondingUseElement);return 3===a.nodeType?a.parentNode:a}var yb=null,zb=null,Ab=null; +function Bb(a){if(a=Cb(a)){if("function"!==typeof yb)throw Error(p(280));var b=a.stateNode;b&&(b=Db(b),yb(a.stateNode,a.type,b))}}function Eb(a){zb?Ab?Ab.push(a):Ab=[a]:zb=a}function Fb(){if(zb){var a=zb,b=Ab;Ab=zb=null;Bb(a);if(b)for(a=0;a>>=0;return 0===a?32:31-(pc(a)/qc|0)|0}var rc=64,sc=4194304; +function tc(a){switch(a&-a){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return a&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return a&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824; +default:return a}}function uc(a,b){var c=a.pendingLanes;if(0===c)return 0;var d=0,e=a.suspendedLanes,f=a.pingedLanes,g=c&268435455;if(0!==g){var h=g&~e;0!==h?d=tc(h):(f&=g,0!==f&&(d=tc(f)))}else g=c&~e,0!==g?d=tc(g):0!==f&&(d=tc(f));if(0===d)return 0;if(0!==b&&b!==d&&0===(b&e)&&(e=d&-d,f=b&-b,e>=f||16===e&&0!==(f&4194240)))return b;0!==(d&4)&&(d|=c&16);b=a.entangledLanes;if(0!==b)for(a=a.entanglements,b&=d;0c;c++)b.push(a);return b} +function Ac(a,b,c){a.pendingLanes|=b;536870912!==b&&(a.suspendedLanes=0,a.pingedLanes=0);a=a.eventTimes;b=31-oc(b);a[b]=c}function Bc(a,b){var c=a.pendingLanes&~b;a.pendingLanes=b;a.suspendedLanes=0;a.pingedLanes=0;a.expiredLanes&=b;a.mutableReadLanes&=b;a.entangledLanes&=b;b=a.entanglements;var d=a.eventTimes;for(a=a.expirationTimes;0=be),ee=String.fromCharCode(32),fe=!1; +function ge(a,b){switch(a){case "keyup":return-1!==$d.indexOf(b.keyCode);case "keydown":return 229!==b.keyCode;case "keypress":case "mousedown":case "focusout":return!0;default:return!1}}function he(a){a=a.detail;return"object"===typeof a&&"data"in a?a.data:null}var ie=!1;function je(a,b){switch(a){case "compositionend":return he(b);case "keypress":if(32!==b.which)return null;fe=!0;return ee;case "textInput":return a=b.data,a===ee&&fe?null:a;default:return null}} +function ke(a,b){if(ie)return"compositionend"===a||!ae&&ge(a,b)?(a=nd(),md=ld=kd=null,ie=!1,a):null;switch(a){case "paste":return null;case "keypress":if(!(b.ctrlKey||b.altKey||b.metaKey)||b.ctrlKey&&b.altKey){if(b.char&&1=b)return{node:c,offset:b-a};a=d}a:{for(;c;){if(c.nextSibling){c=c.nextSibling;break a}c=c.parentNode}c=void 0}c=Je(c)}}function Le(a,b){return a&&b?a===b?!0:a&&3===a.nodeType?!1:b&&3===b.nodeType?Le(a,b.parentNode):"contains"in a?a.contains(b):a.compareDocumentPosition?!!(a.compareDocumentPosition(b)&16):!1:!1} +function Me(){for(var a=window,b=Xa();b instanceof a.HTMLIFrameElement;){try{var c="string"===typeof b.contentWindow.location.href}catch(d){c=!1}if(c)a=b.contentWindow;else break;b=Xa(a.document)}return b}function Ne(a){var b=a&&a.nodeName&&a.nodeName.toLowerCase();return b&&("input"===b&&("text"===a.type||"search"===a.type||"tel"===a.type||"url"===a.type||"password"===a.type)||"textarea"===b||"true"===a.contentEditable)} +function Oe(a){var b=Me(),c=a.focusedElem,d=a.selectionRange;if(b!==c&&c&&c.ownerDocument&&Le(c.ownerDocument.documentElement,c)){if(null!==d&&Ne(c))if(b=d.start,a=d.end,void 0===a&&(a=b),"selectionStart"in c)c.selectionStart=b,c.selectionEnd=Math.min(a,c.value.length);else if(a=(b=c.ownerDocument||document)&&b.defaultView||window,a.getSelection){a=a.getSelection();var e=c.textContent.length,f=Math.min(d.start,e);d=void 0===d.end?f:Math.min(d.end,e);!a.extend&&f>d&&(e=d,d=f,f=e);e=Ke(c,f);var g=Ke(c, +d);e&&g&&(1!==a.rangeCount||a.anchorNode!==e.node||a.anchorOffset!==e.offset||a.focusNode!==g.node||a.focusOffset!==g.offset)&&(b=b.createRange(),b.setStart(e.node,e.offset),a.removeAllRanges(),f>d?(a.addRange(b),a.extend(g.node,g.offset)):(b.setEnd(g.node,g.offset),a.addRange(b)))}b=[];for(a=c;a=a.parentNode;)1===a.nodeType&&b.push({element:a,left:a.scrollLeft,top:a.scrollTop});"function"===typeof c.focus&&c.focus();for(c=0;c=document.documentMode,Qe=null,Re=null,Se=null,Te=!1; +function Ue(a,b,c){var d=c.window===c?c.document:9===c.nodeType?c:c.ownerDocument;Te||null==Qe||Qe!==Xa(d)||(d=Qe,"selectionStart"in d&&Ne(d)?d={start:d.selectionStart,end:d.selectionEnd}:(d=(d.ownerDocument&&d.ownerDocument.defaultView||window).getSelection(),d={anchorNode:d.anchorNode,anchorOffset:d.anchorOffset,focusNode:d.focusNode,focusOffset:d.focusOffset}),Se&&Ie(Se,d)||(Se=d,d=oe(Re,"onSelect"),0Tf||(a.current=Sf[Tf],Sf[Tf]=null,Tf--)}function G(a,b){Tf++;Sf[Tf]=a.current;a.current=b}var Vf={},H=Uf(Vf),Wf=Uf(!1),Xf=Vf;function Yf(a,b){var c=a.type.contextTypes;if(!c)return Vf;var d=a.stateNode;if(d&&d.__reactInternalMemoizedUnmaskedChildContext===b)return d.__reactInternalMemoizedMaskedChildContext;var e={},f;for(f in c)e[f]=b[f];d&&(a=a.stateNode,a.__reactInternalMemoizedUnmaskedChildContext=b,a.__reactInternalMemoizedMaskedChildContext=e);return e} +function Zf(a){a=a.childContextTypes;return null!==a&&void 0!==a}function $f(){E(Wf);E(H)}function ag(a,b,c){if(H.current!==Vf)throw Error(p(168));G(H,b);G(Wf,c)}function bg(a,b,c){var d=a.stateNode;b=b.childContextTypes;if("function"!==typeof d.getChildContext)return c;d=d.getChildContext();for(var e in d)if(!(e in b))throw Error(p(108,Ra(a)||"Unknown",e));return A({},c,d)} +function cg(a){a=(a=a.stateNode)&&a.__reactInternalMemoizedMergedChildContext||Vf;Xf=H.current;G(H,a);G(Wf,Wf.current);return!0}function dg(a,b,c){var d=a.stateNode;if(!d)throw Error(p(169));c?(a=bg(a,b,Xf),d.__reactInternalMemoizedMergedChildContext=a,E(Wf),E(H),G(H,a)):E(Wf);G(Wf,c)}var eg=null,fg=!1,gg=!1;function hg(a){null===eg?eg=[a]:eg.push(a)}function ig(a){fg=!0;hg(a)} +function jg(){if(!gg&&null!==eg){gg=!0;var a=0,b=C;try{var c=eg;for(C=1;a>=g;e-=g;rg=1<<32-oc(b)+e|c<w?(x=u,u=null):x=u.sibling;var n=r(e,u,h[w],k);if(null===n){null===u&&(u=x);break}a&&u&&null===n.alternate&&b(e,u);g=f(n,g,w);null===m?l=n:m.sibling=n;m=n;u=x}if(w===h.length)return c(e,u),I&&tg(e,w),l;if(null===u){for(;ww?(x=m,m=null):x=m.sibling;var t=r(e,m,n.value,k);if(null===t){null===m&&(m=x);break}a&&m&&null===t.alternate&&b(e,m);g=f(t,g,w);null===u?l=t:u.sibling=t;u=t;m=x}if(n.done)return c(e, +m),I&&tg(e,w),l;if(null===m){for(;!n.done;w++,n=h.next())n=q(e,n.value,k),null!==n&&(g=f(n,g,w),null===u?l=n:u.sibling=n,u=n);I&&tg(e,w);return l}for(m=d(e,m);!n.done;w++,n=h.next())n=y(m,e,w,n.value,k),null!==n&&(a&&null!==n.alternate&&m.delete(null===n.key?w:n.key),g=f(n,g,w),null===u?l=n:u.sibling=n,u=n);a&&m.forEach(function(a){return b(e,a)});I&&tg(e,w);return l}function J(a,d,f,h){"object"===typeof f&&null!==f&&f.type===ya&&null===f.key&&(f=f.props.children);if("object"===typeof f&&null!==f){switch(f.$$typeof){case va:a:{for(var k= +f.key,l=d;null!==l;){if(l.key===k){k=f.type;if(k===ya){if(7===l.tag){c(a,l.sibling);d=e(l,f.props.children);d.return=a;a=d;break a}}else if(l.elementType===k||"object"===typeof k&&null!==k&&k.$$typeof===Ha&&uh(k)===l.type){c(a,l.sibling);d=e(l,f.props);d.ref=sh(a,l,f);d.return=a;a=d;break a}c(a,l);break}else b(a,l);l=l.sibling}f.type===ya?(d=Ah(f.props.children,a.mode,h,f.key),d.return=a,a=d):(h=yh(f.type,f.key,f.props,null,a.mode,h),h.ref=sh(a,d,f),h.return=a,a=h)}return g(a);case wa:a:{for(l=f.key;null!== +d;){if(d.key===l)if(4===d.tag&&d.stateNode.containerInfo===f.containerInfo&&d.stateNode.implementation===f.implementation){c(a,d.sibling);d=e(d,f.children||[]);d.return=a;a=d;break a}else{c(a,d);break}else b(a,d);d=d.sibling}d=zh(f,a.mode,h);d.return=a;a=d}return g(a);case Ha:return l=f._init,J(a,d,l(f._payload),h)}if(eb(f))return n(a,d,f,h);if(Ka(f))return t(a,d,f,h);th(a,f)}return"string"===typeof f&&""!==f||"number"===typeof f?(f=""+f,null!==d&&6===d.tag?(c(a,d.sibling),d=e(d,f),d.return=a,a=d): +(c(a,d),d=xh(f,a.mode,h),d.return=a,a=d),g(a)):c(a,d)}return J}var Bh=vh(!0),Ch=vh(!1),Dh={},Eh=Uf(Dh),Fh=Uf(Dh),Gh=Uf(Dh);function Hh(a){if(a===Dh)throw Error(p(174));return a}function Ih(a,b){G(Gh,b);G(Fh,a);G(Eh,Dh);a=b.nodeType;switch(a){case 9:case 11:b=(b=b.documentElement)?b.namespaceURI:lb(null,"");break;default:a=8===a?b.parentNode:b,b=a.namespaceURI||null,a=a.tagName,b=lb(b,a)}E(Eh);G(Eh,b)}function Jh(){E(Eh);E(Fh);E(Gh)} +function Kh(a){Hh(Gh.current);var b=Hh(Eh.current);var c=lb(b,a.type);b!==c&&(G(Fh,a),G(Eh,c))}function Lh(a){Fh.current===a&&(E(Eh),E(Fh))}var M=Uf(0); +function Mh(a){for(var b=a;null!==b;){if(13===b.tag){var c=b.memoizedState;if(null!==c&&(c=c.dehydrated,null===c||"$?"===c.data||"$!"===c.data))return b}else if(19===b.tag&&void 0!==b.memoizedProps.revealOrder){if(0!==(b.flags&128))return b}else if(null!==b.child){b.child.return=b;b=b.child;continue}if(b===a)break;for(;null===b.sibling;){if(null===b.return||b.return===a)return null;b=b.return}b.sibling.return=b.return;b=b.sibling}return null}var Nh=[]; +function Oh(){for(var a=0;ac?c:4;a(!0);var d=Qh.transition;Qh.transition={};try{a(!1),b()}finally{C=c,Qh.transition=d}}function Fi(){return di().memoizedState} +function Gi(a,b,c){var d=lh(a);c={lane:d,action:c,hasEagerState:!1,eagerState:null,next:null};if(Hi(a))Ii(b,c);else if(c=Yg(a,b,c,d),null!==c){var e=L();mh(c,a,d,e);Ji(c,b,d)}} +function ri(a,b,c){var d=lh(a),e={lane:d,action:c,hasEagerState:!1,eagerState:null,next:null};if(Hi(a))Ii(b,e);else{var f=a.alternate;if(0===a.lanes&&(null===f||0===f.lanes)&&(f=b.lastRenderedReducer,null!==f))try{var g=b.lastRenderedState,h=f(g,c);e.hasEagerState=!0;e.eagerState=h;if(He(h,g)){var k=b.interleaved;null===k?(e.next=e,Xg(b)):(e.next=k.next,k.next=e);b.interleaved=e;return}}catch(l){}finally{}c=Yg(a,b,e,d);null!==c&&(e=L(),mh(c,a,d,e),Ji(c,b,d))}} +function Hi(a){var b=a.alternate;return a===N||null!==b&&b===N}function Ii(a,b){Th=Sh=!0;var c=a.pending;null===c?b.next=b:(b.next=c.next,c.next=b);a.pending=b}function Ji(a,b,c){if(0!==(c&4194240)){var d=b.lanes;d&=a.pendingLanes;c|=d;b.lanes=c;Cc(a,c)}} +var ai={readContext:Vg,useCallback:Q,useContext:Q,useEffect:Q,useImperativeHandle:Q,useInsertionEffect:Q,useLayoutEffect:Q,useMemo:Q,useReducer:Q,useRef:Q,useState:Q,useDebugValue:Q,useDeferredValue:Q,useTransition:Q,useMutableSource:Q,useSyncExternalStore:Q,useId:Q,unstable_isNewReconciler:!1},Yh={readContext:Vg,useCallback:function(a,b){ci().memoizedState=[a,void 0===b?null:b];return a},useContext:Vg,useEffect:vi,useImperativeHandle:function(a,b,c){c=null!==c&&void 0!==c?c.concat([a]):null;return ti(4194308, +4,yi.bind(null,b,a),c)},useLayoutEffect:function(a,b){return ti(4194308,4,a,b)},useInsertionEffect:function(a,b){return ti(4,2,a,b)},useMemo:function(a,b){var c=ci();b=void 0===b?null:b;a=a();c.memoizedState=[a,b];return a},useReducer:function(a,b,c){var d=ci();b=void 0!==c?c(b):b;d.memoizedState=d.baseState=b;a={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:a,lastRenderedState:b};d.queue=a;a=a.dispatch=Gi.bind(null,N,a);return[d.memoizedState,a]},useRef:function(a){var b= +ci();a={current:a};return b.memoizedState=a},useState:qi,useDebugValue:Ai,useDeferredValue:function(a){return ci().memoizedState=a},useTransition:function(){var a=qi(!1),b=a[0];a=Ei.bind(null,a[1]);ci().memoizedState=a;return[b,a]},useMutableSource:function(){},useSyncExternalStore:function(a,b,c){var d=N,e=ci();if(I){if(void 0===c)throw Error(p(407));c=c()}else{c=b();if(null===R)throw Error(p(349));0!==(Rh&30)||ni(d,b,c)}e.memoizedState=c;var f={value:c,getSnapshot:b};e.queue=f;vi(ki.bind(null,d, +f,a),[a]);d.flags|=2048;li(9,mi.bind(null,d,f,c,b),void 0,null);return c},useId:function(){var a=ci(),b=R.identifierPrefix;if(I){var c=sg;var d=rg;c=(d&~(1<<32-oc(d)-1)).toString(32)+c;b=":"+b+"R"+c;c=Uh++;0\x3c/script>",a=a.removeChild(a.firstChild)): +"string"===typeof d.is?a=g.createElement(c,{is:d.is}):(a=g.createElement(c),"select"===c&&(g=a,d.multiple?g.multiple=!0:d.size&&(g.size=d.size))):a=g.createElementNS(a,c);a[Of]=b;a[Pf]=d;Aj(a,b,!1,!1);b.stateNode=a;a:{g=vb(c,d);switch(c){case "dialog":D("cancel",a);D("close",a);e=d;break;case "iframe":case "object":case "embed":D("load",a);e=d;break;case "video":case "audio":for(e=0;eHj&&(b.flags|=128,d=!0,Ej(f,!1),b.lanes=4194304)}else{if(!d)if(a=Mh(g),null!==a){if(b.flags|=128,d=!0,c=a.updateQueue,null!==c&&(b.updateQueue=c,b.flags|=4),Ej(f,!0),null===f.tail&&"hidden"===f.tailMode&&!g.alternate&&!I)return S(b),null}else 2*B()-f.renderingStartTime>Hj&&1073741824!==c&&(b.flags|=128,d=!0,Ej(f,!1),b.lanes=4194304);f.isBackwards?(g.sibling=b.child,b.child=g):(c=f.last,null!==c?c.sibling=g:b.child=g,f.last=g)}if(null!==f.tail)return b=f.tail,f.rendering= +b,f.tail=b.sibling,f.renderingStartTime=B(),b.sibling=null,c=M.current,G(M,d?c&1|2:c&1),b;S(b);return null;case 22:case 23:return Ij(),d=null!==b.memoizedState,null!==a&&null!==a.memoizedState!==d&&(b.flags|=8192),d&&0!==(b.mode&1)?0!==(gj&1073741824)&&(S(b),b.subtreeFlags&6&&(b.flags|=8192)):S(b),null;case 24:return null;case 25:return null}throw Error(p(156,b.tag));} +function Jj(a,b){wg(b);switch(b.tag){case 1:return Zf(b.type)&&$f(),a=b.flags,a&65536?(b.flags=a&-65537|128,b):null;case 3:return Jh(),E(Wf),E(H),Oh(),a=b.flags,0!==(a&65536)&&0===(a&128)?(b.flags=a&-65537|128,b):null;case 5:return Lh(b),null;case 13:E(M);a=b.memoizedState;if(null!==a&&null!==a.dehydrated){if(null===b.alternate)throw Error(p(340));Ig()}a=b.flags;return a&65536?(b.flags=a&-65537|128,b):null;case 19:return E(M),null;case 4:return Jh(),null;case 10:return Rg(b.type._context),null;case 22:case 23:return Ij(), +null;case 24:return null;default:return null}}var Kj=!1,U=!1,Lj="function"===typeof WeakSet?WeakSet:Set,V=null;function Mj(a,b){var c=a.ref;if(null!==c)if("function"===typeof c)try{c(null)}catch(d){W(a,b,d)}else c.current=null}function Nj(a,b,c){try{c()}catch(d){W(a,b,d)}}var Oj=!1; +function Pj(a,b){Cf=dd;a=Me();if(Ne(a)){if("selectionStart"in a)var c={start:a.selectionStart,end:a.selectionEnd};else a:{c=(c=a.ownerDocument)&&c.defaultView||window;var d=c.getSelection&&c.getSelection();if(d&&0!==d.rangeCount){c=d.anchorNode;var e=d.anchorOffset,f=d.focusNode;d=d.focusOffset;try{c.nodeType,f.nodeType}catch(F){c=null;break a}var g=0,h=-1,k=-1,l=0,m=0,q=a,r=null;b:for(;;){for(var y;;){q!==c||0!==e&&3!==q.nodeType||(h=g+e);q!==f||0!==d&&3!==q.nodeType||(k=g+d);3===q.nodeType&&(g+= +q.nodeValue.length);if(null===(y=q.firstChild))break;r=q;q=y}for(;;){if(q===a)break b;r===c&&++l===e&&(h=g);r===f&&++m===d&&(k=g);if(null!==(y=q.nextSibling))break;q=r;r=q.parentNode}q=y}c=-1===h||-1===k?null:{start:h,end:k}}else c=null}c=c||{start:0,end:0}}else c=null;Df={focusedElem:a,selectionRange:c};dd=!1;for(V=b;null!==V;)if(b=V,a=b.child,0!==(b.subtreeFlags&1028)&&null!==a)a.return=b,V=a;else for(;null!==V;){b=V;try{var n=b.alternate;if(0!==(b.flags&1024))switch(b.tag){case 0:case 11:case 15:break; +case 1:if(null!==n){var t=n.memoizedProps,J=n.memoizedState,x=b.stateNode,w=x.getSnapshotBeforeUpdate(b.elementType===b.type?t:Lg(b.type,t),J);x.__reactInternalSnapshotBeforeUpdate=w}break;case 3:var u=b.stateNode.containerInfo;1===u.nodeType?u.textContent="":9===u.nodeType&&u.documentElement&&u.removeChild(u.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(p(163));}}catch(F){W(b,b.return,F)}a=b.sibling;if(null!==a){a.return=b.return;V=a;break}V=b.return}n=Oj;Oj=!1;return n} +function Qj(a,b,c){var d=b.updateQueue;d=null!==d?d.lastEffect:null;if(null!==d){var e=d=d.next;do{if((e.tag&a)===a){var f=e.destroy;e.destroy=void 0;void 0!==f&&Nj(b,c,f)}e=e.next}while(e!==d)}}function Rj(a,b){b=b.updateQueue;b=null!==b?b.lastEffect:null;if(null!==b){var c=b=b.next;do{if((c.tag&a)===a){var d=c.create;c.destroy=d()}c=c.next}while(c!==b)}}function Sj(a){var b=a.ref;if(null!==b){var c=a.stateNode;switch(a.tag){case 5:a=c;break;default:a=c}"function"===typeof b?b(a):b.current=a}} +function Tj(a){var b=a.alternate;null!==b&&(a.alternate=null,Tj(b));a.child=null;a.deletions=null;a.sibling=null;5===a.tag&&(b=a.stateNode,null!==b&&(delete b[Of],delete b[Pf],delete b[of],delete b[Qf],delete b[Rf]));a.stateNode=null;a.return=null;a.dependencies=null;a.memoizedProps=null;a.memoizedState=null;a.pendingProps=null;a.stateNode=null;a.updateQueue=null}function Uj(a){return 5===a.tag||3===a.tag||4===a.tag} +function Vj(a){a:for(;;){for(;null===a.sibling;){if(null===a.return||Uj(a.return))return null;a=a.return}a.sibling.return=a.return;for(a=a.sibling;5!==a.tag&&6!==a.tag&&18!==a.tag;){if(a.flags&2)continue a;if(null===a.child||4===a.tag)continue a;else a.child.return=a,a=a.child}if(!(a.flags&2))return a.stateNode}} +function Wj(a,b,c){var d=a.tag;if(5===d||6===d)a=a.stateNode,b?8===c.nodeType?c.parentNode.insertBefore(a,b):c.insertBefore(a,b):(8===c.nodeType?(b=c.parentNode,b.insertBefore(a,c)):(b=c,b.appendChild(a)),c=c._reactRootContainer,null!==c&&void 0!==c||null!==b.onclick||(b.onclick=Bf));else if(4!==d&&(a=a.child,null!==a))for(Wj(a,b,c),a=a.sibling;null!==a;)Wj(a,b,c),a=a.sibling} +function Xj(a,b,c){var d=a.tag;if(5===d||6===d)a=a.stateNode,b?c.insertBefore(a,b):c.appendChild(a);else if(4!==d&&(a=a.child,null!==a))for(Xj(a,b,c),a=a.sibling;null!==a;)Xj(a,b,c),a=a.sibling}var X=null,Yj=!1;function Zj(a,b,c){for(c=c.child;null!==c;)ak(a,b,c),c=c.sibling} +function ak(a,b,c){if(lc&&"function"===typeof lc.onCommitFiberUnmount)try{lc.onCommitFiberUnmount(kc,c)}catch(h){}switch(c.tag){case 5:U||Mj(c,b);case 6:var d=X,e=Yj;X=null;Zj(a,b,c);X=d;Yj=e;null!==X&&(Yj?(a=X,c=c.stateNode,8===a.nodeType?a.parentNode.removeChild(c):a.removeChild(c)):X.removeChild(c.stateNode));break;case 18:null!==X&&(Yj?(a=X,c=c.stateNode,8===a.nodeType?Kf(a.parentNode,c):1===a.nodeType&&Kf(a,c),bd(a)):Kf(X,c.stateNode));break;case 4:d=X;e=Yj;X=c.stateNode.containerInfo;Yj=!0; +Zj(a,b,c);X=d;Yj=e;break;case 0:case 11:case 14:case 15:if(!U&&(d=c.updateQueue,null!==d&&(d=d.lastEffect,null!==d))){e=d=d.next;do{var f=e,g=f.destroy;f=f.tag;void 0!==g&&(0!==(f&2)?Nj(c,b,g):0!==(f&4)&&Nj(c,b,g));e=e.next}while(e!==d)}Zj(a,b,c);break;case 1:if(!U&&(Mj(c,b),d=c.stateNode,"function"===typeof d.componentWillUnmount))try{d.props=c.memoizedProps,d.state=c.memoizedState,d.componentWillUnmount()}catch(h){W(c,b,h)}Zj(a,b,c);break;case 21:Zj(a,b,c);break;case 22:c.mode&1?(U=(d=U)||null!== +c.memoizedState,Zj(a,b,c),U=d):Zj(a,b,c);break;default:Zj(a,b,c)}}function bk(a){var b=a.updateQueue;if(null!==b){a.updateQueue=null;var c=a.stateNode;null===c&&(c=a.stateNode=new Lj);b.forEach(function(b){var d=ck.bind(null,a,b);c.has(b)||(c.add(b),b.then(d,d))})}} +function dk(a,b){var c=b.deletions;if(null!==c)for(var d=0;de&&(e=g);d&=~f}d=e;d=B()-d;d=(120>d?120:480>d?480:1080>d?1080:1920>d?1920:3E3>d?3E3:4320>d?4320:1960*mk(d/1960))-d;if(10a?16:a;if(null===xk)var d=!1;else{a=xk;xk=null;yk=0;if(0!==(K&6))throw Error(p(331));var e=K;K|=4;for(V=a.current;null!==V;){var f=V,g=f.child;if(0!==(V.flags&16)){var h=f.deletions;if(null!==h){for(var k=0;kB()-gk?Lk(a,0):sk|=c);Ek(a,b)}function Zk(a,b){0===b&&(0===(a.mode&1)?b=1:(b=sc,sc<<=1,0===(sc&130023424)&&(sc=4194304)));var c=L();a=Zg(a,b);null!==a&&(Ac(a,b,c),Ek(a,c))}function vj(a){var b=a.memoizedState,c=0;null!==b&&(c=b.retryLane);Zk(a,c)} +function ck(a,b){var c=0;switch(a.tag){case 13:var d=a.stateNode;var e=a.memoizedState;null!==e&&(c=e.retryLane);break;case 19:d=a.stateNode;break;default:throw Error(p(314));}null!==d&&d.delete(b);Zk(a,c)}var Wk; +Wk=function(a,b,c){if(null!==a)if(a.memoizedProps!==b.pendingProps||Wf.current)Ug=!0;else{if(0===(a.lanes&c)&&0===(b.flags&128))return Ug=!1,zj(a,b,c);Ug=0!==(a.flags&131072)?!0:!1}else Ug=!1,I&&0!==(b.flags&1048576)&&ug(b,ng,b.index);b.lanes=0;switch(b.tag){case 2:var d=b.type;jj(a,b);a=b.pendingProps;var e=Yf(b,H.current);Tg(b,c);e=Xh(null,b,d,a,e,c);var f=bi();b.flags|=1;"object"===typeof e&&null!==e&&"function"===typeof e.render&&void 0===e.$$typeof?(b.tag=1,b.memoizedState=null,b.updateQueue= +null,Zf(d)?(f=!0,cg(b)):f=!1,b.memoizedState=null!==e.state&&void 0!==e.state?e.state:null,ah(b),e.updater=nh,b.stateNode=e,e._reactInternals=b,rh(b,d,a,c),b=kj(null,b,d,!0,f,c)):(b.tag=0,I&&f&&vg(b),Yi(null,b,e,c),b=b.child);return b;case 16:d=b.elementType;a:{jj(a,b);a=b.pendingProps;e=d._init;d=e(d._payload);b.type=d;e=b.tag=$k(d);a=Lg(d,a);switch(e){case 0:b=dj(null,b,d,a,c);break a;case 1:b=ij(null,b,d,a,c);break a;case 11:b=Zi(null,b,d,a,c);break a;case 14:b=aj(null,b,d,Lg(d.type,a),c);break a}throw Error(p(306, +d,""));}return b;case 0:return d=b.type,e=b.pendingProps,e=b.elementType===d?e:Lg(d,e),dj(a,b,d,e,c);case 1:return d=b.type,e=b.pendingProps,e=b.elementType===d?e:Lg(d,e),ij(a,b,d,e,c);case 3:a:{lj(b);if(null===a)throw Error(p(387));d=b.pendingProps;f=b.memoizedState;e=f.element;bh(a,b);gh(b,d,null,c);var g=b.memoizedState;d=g.element;if(f.isDehydrated)if(f={element:d,isDehydrated:!1,cache:g.cache,pendingSuspenseBoundaries:g.pendingSuspenseBoundaries,transitions:g.transitions},b.updateQueue.baseState= +f,b.memoizedState=f,b.flags&256){e=Ki(Error(p(423)),b);b=mj(a,b,d,c,e);break a}else if(d!==e){e=Ki(Error(p(424)),b);b=mj(a,b,d,c,e);break a}else for(yg=Lf(b.stateNode.containerInfo.firstChild),xg=b,I=!0,zg=null,c=Ch(b,null,d,c),b.child=c;c;)c.flags=c.flags&-3|4096,c=c.sibling;else{Ig();if(d===e){b=$i(a,b,c);break a}Yi(a,b,d,c)}b=b.child}return b;case 5:return Kh(b),null===a&&Eg(b),d=b.type,e=b.pendingProps,f=null!==a?a.memoizedProps:null,g=e.children,Ef(d,e)?g=null:null!==f&&Ef(d,f)&&(b.flags|=32), +hj(a,b),Yi(a,b,g,c),b.child;case 6:return null===a&&Eg(b),null;case 13:return pj(a,b,c);case 4:return Ih(b,b.stateNode.containerInfo),d=b.pendingProps,null===a?b.child=Bh(b,null,d,c):Yi(a,b,d,c),b.child;case 11:return d=b.type,e=b.pendingProps,e=b.elementType===d?e:Lg(d,e),Zi(a,b,d,e,c);case 7:return Yi(a,b,b.pendingProps,c),b.child;case 8:return Yi(a,b,b.pendingProps.children,c),b.child;case 12:return Yi(a,b,b.pendingProps.children,c),b.child;case 10:a:{d=b.type._context;e=b.pendingProps;f=b.memoizedProps; +g=e.value;G(Mg,d._currentValue);d._currentValue=g;if(null!==f)if(He(f.value,g)){if(f.children===e.children&&!Wf.current){b=$i(a,b,c);break a}}else for(f=b.child,null!==f&&(f.return=b);null!==f;){var h=f.dependencies;if(null!==h){g=f.child;for(var k=h.firstContext;null!==k;){if(k.context===d){if(1===f.tag){k=ch(-1,c&-c);k.tag=2;var l=f.updateQueue;if(null!==l){l=l.shared;var m=l.pending;null===m?k.next=k:(k.next=m.next,m.next=k);l.pending=k}}f.lanes|=c;k=f.alternate;null!==k&&(k.lanes|=c);Sg(f.return, +c,b);h.lanes|=c;break}k=k.next}}else if(10===f.tag)g=f.type===b.type?null:f.child;else if(18===f.tag){g=f.return;if(null===g)throw Error(p(341));g.lanes|=c;h=g.alternate;null!==h&&(h.lanes|=c);Sg(g,c,b);g=f.sibling}else g=f.child;if(null!==g)g.return=f;else for(g=f;null!==g;){if(g===b){g=null;break}f=g.sibling;if(null!==f){f.return=g.return;g=f;break}g=g.return}f=g}Yi(a,b,e.children,c);b=b.child}return b;case 9:return e=b.type,d=b.pendingProps.children,Tg(b,c),e=Vg(e),d=d(e),b.flags|=1,Yi(a,b,d,c), +b.child;case 14:return d=b.type,e=Lg(d,b.pendingProps),e=Lg(d.type,e),aj(a,b,d,e,c);case 15:return cj(a,b,b.type,b.pendingProps,c);case 17:return d=b.type,e=b.pendingProps,e=b.elementType===d?e:Lg(d,e),jj(a,b),b.tag=1,Zf(d)?(a=!0,cg(b)):a=!1,Tg(b,c),ph(b,d,e),rh(b,d,e,c),kj(null,b,d,!0,a,c);case 19:return yj(a,b,c);case 22:return ej(a,b,c)}throw Error(p(156,b.tag));};function Gk(a,b){return ac(a,b)} +function al(a,b,c,d){this.tag=a;this.key=c;this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null;this.index=0;this.ref=null;this.pendingProps=b;this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null;this.mode=d;this.subtreeFlags=this.flags=0;this.deletions=null;this.childLanes=this.lanes=0;this.alternate=null}function Bg(a,b,c,d){return new al(a,b,c,d)}function bj(a){a=a.prototype;return!(!a||!a.isReactComponent)} +function $k(a){if("function"===typeof a)return bj(a)?1:0;if(void 0!==a&&null!==a){a=a.$$typeof;if(a===Da)return 11;if(a===Ga)return 14}return 2} +function wh(a,b){var c=a.alternate;null===c?(c=Bg(a.tag,b,a.key,a.mode),c.elementType=a.elementType,c.type=a.type,c.stateNode=a.stateNode,c.alternate=a,a.alternate=c):(c.pendingProps=b,c.type=a.type,c.flags=0,c.subtreeFlags=0,c.deletions=null);c.flags=a.flags&14680064;c.childLanes=a.childLanes;c.lanes=a.lanes;c.child=a.child;c.memoizedProps=a.memoizedProps;c.memoizedState=a.memoizedState;c.updateQueue=a.updateQueue;b=a.dependencies;c.dependencies=null===b?null:{lanes:b.lanes,firstContext:b.firstContext}; +c.sibling=a.sibling;c.index=a.index;c.ref=a.ref;return c} +function yh(a,b,c,d,e,f){var g=2;d=a;if("function"===typeof a)bj(a)&&(g=1);else if("string"===typeof a)g=5;else a:switch(a){case ya:return Ah(c.children,e,f,b);case za:g=8;e|=8;break;case Aa:return a=Bg(12,c,b,e|2),a.elementType=Aa,a.lanes=f,a;case Ea:return a=Bg(13,c,b,e),a.elementType=Ea,a.lanes=f,a;case Fa:return a=Bg(19,c,b,e),a.elementType=Fa,a.lanes=f,a;case Ia:return qj(c,e,f,b);default:if("object"===typeof a&&null!==a)switch(a.$$typeof){case Ba:g=10;break a;case Ca:g=9;break a;case Da:g=11; +break a;case Ga:g=14;break a;case Ha:g=16;d=null;break a}throw Error(p(130,null==a?a:typeof a,""));}b=Bg(g,c,b,e);b.elementType=a;b.type=d;b.lanes=f;return b}function Ah(a,b,c,d){a=Bg(7,a,d,b);a.lanes=c;return a}function qj(a,b,c,d){a=Bg(22,a,d,b);a.elementType=Ia;a.lanes=c;a.stateNode={isHidden:!1};return a}function xh(a,b,c){a=Bg(6,a,null,b);a.lanes=c;return a} +function zh(a,b,c){b=Bg(4,null!==a.children?a.children:[],a.key,b);b.lanes=c;b.stateNode={containerInfo:a.containerInfo,pendingChildren:null,implementation:a.implementation};return b} +function bl(a,b,c,d,e){this.tag=b;this.containerInfo=a;this.finishedWork=this.pingCache=this.current=this.pendingChildren=null;this.timeoutHandle=-1;this.callbackNode=this.pendingContext=this.context=null;this.callbackPriority=0;this.eventTimes=zc(0);this.expirationTimes=zc(-1);this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0;this.entanglements=zc(0);this.identifierPrefix=d;this.onRecoverableError=e;this.mutableSourceEagerHydrationData= +null}function cl(a,b,c,d,e,f,g,h,k){a=new bl(a,b,c,h,k);1===b?(b=1,!0===f&&(b|=8)):b=0;f=Bg(3,null,null,b);a.current=f;f.stateNode=a;f.memoizedState={element:d,isDehydrated:c,cache:null,transitions:null,pendingSuspenseBoundaries:null};ah(f);return a}function dl(a,b,c){var d=3>>1,e=a[d];if(0>>1;dg(C,c))ng(x,C)?(a[d]=x,a[n]=c,d=n):(a[d]=C,a[m]=c,d=m);else if(ng(x,c))a[d]=x,a[n]=c,d=n;else break a}}return b} +function g(a,b){var c=a.sortIndex-b.sortIndex;return 0!==c?c:a.id-b.id}if("object"===typeof performance&&"function"===typeof performance.now){var l=performance;exports.unstable_now=function(){return l.now()}}else{var p=Date,q=p.now();exports.unstable_now=function(){return p.now()-q}}var r=[],t=[],u=1,v=null,y=3,z=!1,A=!1,B=!1,D="function"===typeof setTimeout?setTimeout:null,E="function"===typeof clearTimeout?clearTimeout:null,F="undefined"!==typeof setImmediate?setImmediate:null; +"undefined"!==typeof navigator&&void 0!==navigator.scheduling&&void 0!==navigator.scheduling.isInputPending&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function G(a){for(var b=h(t);null!==b;){if(null===b.callback)k(t);else if(b.startTime<=a)k(t),b.sortIndex=b.expirationTime,f(r,b);else break;b=h(t)}}function H(a){B=!1;G(a);if(!A)if(null!==h(r))A=!0,I(J);else{var b=h(t);null!==b&&K(H,b.startTime-a)}} +function J(a,b){A=!1;B&&(B=!1,E(L),L=-1);z=!0;var c=y;try{G(b);for(v=h(r);null!==v&&(!(v.expirationTime>b)||a&&!M());){var d=v.callback;if("function"===typeof d){v.callback=null;y=v.priorityLevel;var e=d(v.expirationTime<=b);b=exports.unstable_now();"function"===typeof e?v.callback=e:v===h(r)&&k(r);G(b)}else k(r);v=h(r)}if(null!==v)var w=!0;else{var m=h(t);null!==m&&K(H,m.startTime-b);w=!1}return w}finally{v=null,y=c,z=!1}}var N=!1,O=null,L=-1,P=5,Q=-1; +function M(){return exports.unstable_now()-Qa||125d?(a.sortIndex=c,f(t,a),null===h(r)&&a===h(t)&&(B?(E(L),L=-1):B=!0,K(H,c-d))):(a.sortIndex=e,f(r,a),A||z||(A=!0,I(J)));return a}; +exports.unstable_shouldYield=M;exports.unstable_wrapCallback=function(a){var b=y;return function(){var c=y;y=b;try{return a.apply(this,arguments)}finally{y=c}}}; + + +/***/ }), + +/***/ 3840: +/***/ (function(module, __unused_webpack_exports, __webpack_require__) { + + + +if (true) { + module.exports = __webpack_require__(53); +} else {} + + +/***/ }) + +}]); \ No newline at end of file diff --git a/crates/swc_ecma_minifier/tests/fixture/next/43208/static/chunks/main-0fdc0c4ebee9ebae/input.js b/crates/swc_ecma_minifier/tests/fixture/next/43208/static/chunks/main-0fdc0c4ebee9ebae/input.js new file mode 100644 index 000000000000..cffe7172cd41 --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/next/43208/static/chunks/main-0fdc0c4ebee9ebae/input.js @@ -0,0 +1,5682 @@ +(self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([[179],{ + +/***/ 932: +/***/ (function(__unused_webpack_module, exports) { + +"use strict"; +var __webpack_unused_export__; + +__webpack_unused_export__ = ({ + value: true +}); +Object.defineProperty(exports, "Z", ({ + enumerable: true, + get: function() { + return _asyncToGenerator; + } +})); +function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { + try { + var info = gen[key](arg); + var value = info.value; + } catch (error) { + reject(error); + return; + } + if (info.done) { + resolve(value); + } else { + Promise.resolve(value).then(_next, _throw); + } +} +function _asyncToGenerator(fn) { + return function() { + var self = this, args = arguments; + return new Promise(function(resolve, reject) { + var gen = fn.apply(self, args); + function _next(value) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); + } + function _throw(err) { + asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); + } + _next(undefined); + }); + }; +} + + +/***/ }), + +/***/ 6495: +/***/ (function(__unused_webpack_module, exports) { + +"use strict"; +var __webpack_unused_export__; + +__webpack_unused_export__ = ({ + value: true +}); +Object.defineProperty(exports, "Z", ({ + enumerable: true, + get: function() { + return _extends; + } +})); +function extends_() { + extends_ = Object.assign || function(target) { + for(var i = 1; i < arguments.length; i++){ + var source = arguments[i]; + for(var key in source){ + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } + } + } + return target; + }; + return extends_.apply(this, arguments); +} +function _extends() { + return extends_.apply(this, arguments); +} + + +/***/ }), + +/***/ 2648: +/***/ (function(__unused_webpack_module, exports) { + +"use strict"; +var __webpack_unused_export__; + +__webpack_unused_export__ = ({ + value: true +}); +Object.defineProperty(exports, "Z", ({ + enumerable: true, + get: function() { + return _interopRequireDefault; + } +})); +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; +} + + +/***/ }), + +/***/ 1598: +/***/ (function(__unused_webpack_module, exports) { + +"use strict"; +var __webpack_unused_export__; + +__webpack_unused_export__ = ({ + value: true +}); +Object.defineProperty(exports, "Z", ({ + enumerable: true, + get: function() { + return _interopRequireWildcard; + } +})); +function _getRequireWildcardCache(nodeInterop) { + if (typeof WeakMap !== "function") return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); +} +function _interopRequireWildcard(obj, nodeInterop) { + if (!nodeInterop && obj && obj.__esModule) { + return obj; + } + if (obj === null || typeof obj !== "object" && typeof obj !== "function") { + return { + default: obj + }; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = {}; + var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; + for(var key in obj){ + if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; +} + + +/***/ }), + +/***/ 7273: +/***/ (function(__unused_webpack_module, exports) { + +"use strict"; +var __webpack_unused_export__; + +__webpack_unused_export__ = ({ + value: true +}); +Object.defineProperty(exports, "Z", ({ + enumerable: true, + get: function() { + return _objectWithoutPropertiesLoose; + } +})); +function _objectWithoutPropertiesLoose(source, excluded) { + if (source == null) return {}; + var target = {}; + var sourceKeys = Object.keys(source); + var key, i; + for(i = 0; i < sourceKeys.length; i++){ + key = sourceKeys[i]; + if (excluded.indexOf(key) >= 0) continue; + target[key] = source[key]; + } + return target; +} + + +/***/ }), + +/***/ 37: +/***/ (function() { + +"trimStart"in String.prototype||(String.prototype.trimStart=String.prototype.trimLeft),"trimEnd"in String.prototype||(String.prototype.trimEnd=String.prototype.trimRight),"description"in Symbol.prototype||Object.defineProperty(Symbol.prototype,"description",{configurable:!0,get:function(){var t=/\((.*)\)/.exec(this.toString());return t?t[1]:void 0}}),Array.prototype.flat||(Array.prototype.flat=function(t,r){return r=this.concat.apply([],this),t>1&&r.some(Array.isArray)?r.flat(t-1):r},Array.prototype.flatMap=function(t,r){return this.map(t,r).flat()}),Promise.prototype.finally||(Promise.prototype.finally=function(t){if("function"!=typeof t)return this.then(t,t);var r=this.constructor||Promise;return this.then(function(o){return r.resolve(t()).then(function(){return o})},function(o){return r.resolve(t()).then(function(){throw o})})}),Object.fromEntries||(Object.fromEntries=function(t){return Array.from(t).reduce(function(t,r){return t[r[0]]=r[1],t},{})}); + + +/***/ }), + +/***/ 3468: +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +exports.addBasePath = addBasePath; +var _addPathPrefix = __webpack_require__(4135); +var _normalizeTrailingSlash = __webpack_require__(2700); +const basePath = false || ""; +function addBasePath(path, required) { + if (false) {} + return (0, _normalizeTrailingSlash).normalizePathTrailingSlash((0, _addPathPrefix).addPathPrefix(path, basePath)); +} +if ((typeof exports.default === "function" || typeof exports.default === "object" && exports.default !== null) && typeof exports.default.__esModule === "undefined") { + Object.defineProperty(exports.default, "__esModule", { + value: true + }); + Object.assign(exports.default, exports); + module.exports = exports.default; +} //# sourceMappingURL=add-base-path.js.map + + +/***/ }), + +/***/ 4465: +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +exports.addLocale = void 0; +var _normalizeTrailingSlash = __webpack_require__(2700); +const addLocale = function(path) { + for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){ + args[_key - 1] = arguments[_key]; + } + if (false) {} + return path; +}; +exports.addLocale = addLocale; +if ((typeof exports.default === "function" || typeof exports.default === "object" && exports.default !== null) && typeof exports.default.__esModule === "undefined") { + Object.defineProperty(exports.default, "__esModule", { + value: true + }); + Object.assign(exports.default, exports); + module.exports = exports.default; +} //# sourceMappingURL=add-locale.js.map + + +/***/ }), + +/***/ 4643: +/***/ (function(module, exports) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +exports.detectDomainLocale = void 0; +const detectDomainLocale = function() { + for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ + args[_key] = arguments[_key]; + } + if (false) {} +}; +exports.detectDomainLocale = detectDomainLocale; +if ((typeof exports.default === "function" || typeof exports.default === "object" && exports.default !== null) && typeof exports.default.__esModule === "undefined") { + Object.defineProperty(exports.default, "__esModule", { + value: true + }); + Object.assign(exports.default, exports); + module.exports = exports.default; +} //# sourceMappingURL=detect-domain-locale.js.map + + +/***/ }), + +/***/ 928: +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +exports.hasBasePath = hasBasePath; +var _pathHasPrefix = __webpack_require__(3210); +const basePath = false || ""; +function hasBasePath(path) { + return (0, _pathHasPrefix).pathHasPrefix(path, basePath); +} +if ((typeof exports.default === "function" || typeof exports.default === "object" && exports.default !== null) && typeof exports.default.__esModule === "undefined") { + Object.defineProperty(exports.default, "__esModule", { + value: true + }); + Object.assign(exports.default, exports); + module.exports = exports.default; +} //# sourceMappingURL=has-base-path.js.map + + +/***/ }), + +/***/ 1831: +/***/ (function(module, exports) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +exports["default"] = initHeadManager; +exports.isEqualNode = isEqualNode; +exports.DOMAttributeNames = void 0; +function initHeadManager() { + return { + mountedInstances: new Set(), + updateHead: (head)=>{ + const tags = {}; + head.forEach((h)=>{ + if (// it won't be inlined. In this case revert to the original behavior + h.type === "link" && h.props["data-optimized-fonts"]) { + if (document.querySelector('style[data-href="'.concat(h.props["data-href"], '"]'))) { + return; + } else { + h.props.href = h.props["data-href"]; + h.props["data-href"] = undefined; + } + } + const components = tags[h.type] || []; + components.push(h); + tags[h.type] = components; + }); + const titleComponent = tags.title ? tags.title[0] : null; + let title = ""; + if (titleComponent) { + const { children } = titleComponent.props; + title = typeof children === "string" ? children : Array.isArray(children) ? children.join("") : ""; + } + if (title !== document.title) document.title = title; + [ + "meta", + "base", + "link", + "style", + "script" + ].forEach((type)=>{ + updateElements(type, tags[type] || []); + }); + } + }; +} +const DOMAttributeNames = { + acceptCharset: "accept-charset", + className: "class", + htmlFor: "for", + httpEquiv: "http-equiv", + noModule: "noModule" +}; +exports.DOMAttributeNames = DOMAttributeNames; +function reactElementToDOM(param) { + let { type , props } = param; + const el = document.createElement(type); + for(const p in props){ + if (!props.hasOwnProperty(p)) continue; + if (p === "children" || p === "dangerouslySetInnerHTML") continue; + // we don't render undefined props to the DOM + if (props[p] === undefined) continue; + const attr = DOMAttributeNames[p] || p.toLowerCase(); + if (type === "script" && (attr === "async" || attr === "defer" || attr === "noModule")) { + el[attr] = !!props[p]; + } else { + el.setAttribute(attr, props[p]); + } + } + const { children , dangerouslySetInnerHTML } = props; + if (dangerouslySetInnerHTML) { + el.innerHTML = dangerouslySetInnerHTML.__html || ""; + } else if (children) { + el.textContent = typeof children === "string" ? children : Array.isArray(children) ? children.join("") : ""; + } + return el; +} +function isEqualNode(oldTag, newTag) { + if (oldTag instanceof HTMLElement && newTag instanceof HTMLElement) { + const nonce = newTag.getAttribute("nonce"); + // Only strip the nonce if `oldTag` has had it stripped. An element's nonce attribute will not + // be stripped if there is no content security policy response header that includes a nonce. + if (nonce && !oldTag.getAttribute("nonce")) { + const cloneTag = newTag.cloneNode(true); + cloneTag.setAttribute("nonce", ""); + cloneTag.nonce = nonce; + return nonce === oldTag.nonce && oldTag.isEqualNode(cloneTag); + } + } + return oldTag.isEqualNode(newTag); +} +function updateElements(type, components) { + const headEl = document.getElementsByTagName("head")[0]; + const headCountEl = headEl.querySelector("meta[name=next-head-count]"); + if (false) {} + const headCount = Number(headCountEl.content); + const oldTags = []; + for(let i = 0, j = headCountEl.previousElementSibling; i < headCount; i++, j = (j == null ? void 0 : j.previousElementSibling) || null){ + var ref; + if ((j == null ? void 0 : (ref = j.tagName) == null ? void 0 : ref.toLowerCase()) === type) { + oldTags.push(j); + } + } + const newTags = components.map(reactElementToDOM).filter((newTag)=>{ + for(let k = 0, len = oldTags.length; k < len; k++){ + const oldTag = oldTags[k]; + if (isEqualNode(oldTag, newTag)) { + oldTags.splice(k, 1); + return false; + } + } + return true; + }); + oldTags.forEach((t)=>{ + var ref; + return (ref = t.parentNode) == null ? void 0 : ref.removeChild(t); + }); + newTags.forEach((t)=>headEl.insertBefore(t, headCountEl)); + headCountEl.content = (headCount - oldTags.length + newTags.length).toString(); +} +if ((typeof exports.default === "function" || typeof exports.default === "object" && exports.default !== null) && typeof exports.default.__esModule === "undefined") { + Object.defineProperty(exports.default, "__esModule", { + value: true + }); + Object.assign(exports.default, exports); + module.exports = exports.default; +} //# sourceMappingURL=head-manager.js.map + + +/***/ }), + +/***/ 4534: +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +const _interopRequireWildcard = (__webpack_require__(1598)/* ["default"] */ .Z); +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +exports.initialize = initialize; +exports.hydrate = hydrate; +exports.emitter = exports.router = exports.version = void 0; +var _async_to_generator = (__webpack_require__(932)/* ["default"] */ .Z); +var _extends = (__webpack_require__(6495)/* ["default"] */ .Z); +var _interop_require_default = (__webpack_require__(2648)/* ["default"] */ .Z); +var _interop_require_wildcard = (__webpack_require__(1598)/* ["default"] */ .Z); +__webpack_require__(37); +var _react = _interop_require_default(__webpack_require__(7294)); +var _client = _interop_require_default(__webpack_require__(745)); +var _headManagerContext = __webpack_require__(4664); +var _mitt = _interop_require_default(__webpack_require__(8550)); +var _routerContext = __webpack_require__(2692); +var _isDynamic = __webpack_require__(6238); +var _querystring = __webpack_require__(4919); +var _runtimeConfig = __webpack_require__(6949); +var _utils = __webpack_require__(670); +var _portal = __webpack_require__(7345); +var _headManager = _interop_require_default(__webpack_require__(1831)); +var _pageLoader = _interop_require_default(__webpack_require__(976)); +var _performanceRelayer = _interop_require_default(__webpack_require__(659)); +var _routeAnnouncer = __webpack_require__(8483); +var _router = __webpack_require__(880); +var _isError = __webpack_require__(676); +var _imageConfigContext = __webpack_require__(8730); +var _removeBasePath = __webpack_require__(2813); +var _hasBasePath = __webpack_require__(928); +var _appRouterContext = __webpack_require__(8245); +var _adapters = __webpack_require__(401); +var _hooksClientContext = __webpack_require__(8914); +const version = "13.0.5-canary.4"; +exports.version = version; +let router; +exports.router = router; +const emitter = (0, _mitt).default(); +exports.emitter = emitter; +const looseToArray = (input)=>[].slice.call(input); +let initialData; +let defaultLocale = undefined; +let asPath; +let pageLoader; +let appElement; +let headManager; +let initialMatchesMiddleware = false; +let lastAppProps; +let lastRenderReject; +let webpackHMR; +let CachedApp, onPerfEntry; +let CachedComponent; +self.__next_require__ = __webpack_require__; +class Container extends _react.default.Component { + componentDidCatch(componentErr, info) { + this.props.fn(componentErr, info); + } + componentDidMount() { + this.scrollToHash(); + // We need to replace the router state if: + // - the page was (auto) exported and has a query string or search (hash) + // - it was auto exported and is a dynamic route (to provide params) + // - if it is a client-side skeleton (fallback render) + // - if middleware matches the current page (may have rewrite params) + // - if rewrites in next.config.js match (may have rewrite params) + if (router.isSsr && // We don't update for 404 requests as this can modify + // the asPath unexpectedly e.g. adding basePath when + // it wasn't originally present + initialData.page !== "/404" && initialData.page !== "/_error" && (initialData.isFallback || initialData.nextExport && ((0, _isDynamic).isDynamicRoute(router.pathname) || location.search || false || initialMatchesMiddleware) || initialData.props && initialData.props.__N_SSG && (location.search || false || initialMatchesMiddleware))) { + // update query on mount for exported pages + router.replace(router.pathname + "?" + String((0, _querystring).assign((0, _querystring).urlQueryToSearchParams(router.query), new URLSearchParams(location.search))), asPath, { + // @ts-ignore + // WARNING: `_h` is an internal option for handing Next.js + // client-side hydration. Your app should _never_ use this property. + // It may change at any time without notice. + _h: 1, + // Fallback pages must trigger the data fetch, so the transition is + // not shallow. + // Other pages (strictly updating query) happens shallowly, as data + // requirements would already be present. + shallow: !initialData.isFallback && !initialMatchesMiddleware + }).catch((err)=>{ + if (!err.cancelled) throw err; + }); + } + } + componentDidUpdate() { + this.scrollToHash(); + } + scrollToHash() { + let { hash } = location; + hash = hash && hash.substring(1); + if (!hash) return; + const el = document.getElementById(hash); + if (!el) return; + // If we call scrollIntoView() in here without a setTimeout + // it won't scroll properly. + setTimeout(()=>el.scrollIntoView(), 0); + } + render() { + if (true) { + return this.props.children; + } else {} + } +} +function initialize() { + return _initialize.apply(this, arguments); +} +function _initialize() { + _initialize = _async_to_generator(function*() { + let opts = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; + // This makes sure this specific lines are removed in production + if (false) {} + initialData = JSON.parse(document.getElementById("__NEXT_DATA__").textContent); + window.__NEXT_DATA__ = initialData; + defaultLocale = initialData.defaultLocale; + const prefix = initialData.assetPrefix || ""; + // With dynamic assetPrefix it's no longer possible to set assetPrefix at the build time + // So, this is how we do it in the client side at runtime + __webpack_require__.p = "".concat(prefix, "/_next/") //eslint-disable-line + ; + // Initialize next/config with the environment configuration + (0, _runtimeConfig).setConfig({ + serverRuntimeConfig: {}, + publicRuntimeConfig: initialData.runtimeConfig || {} + }); + asPath = (0, _utils).getURL(); + // make sure not to attempt stripping basePath for 404s + if ((0, _hasBasePath).hasBasePath(asPath)) { + asPath = (0, _removeBasePath).removeBasePath(asPath); + } + if (false) {} + if (initialData.scriptLoader) { + const { initScriptLoader } = __webpack_require__(3573); + initScriptLoader(initialData.scriptLoader); + } + pageLoader = new _pageLoader.default(initialData.buildId, prefix); + const register = (param)=>{ + let [r, f] = param; + return pageLoader.routeLoader.onEntrypoint(r, f); + }; + if (window.__NEXT_P) { + // Defer page registration for another tick. This will increase the overall + // latency in hydrating the page, but reduce the total blocking time. + window.__NEXT_P.map((p)=>setTimeout(()=>register(p), 0)); + } + window.__NEXT_P = []; + window.__NEXT_P.push = register; + headManager = (0, _headManager).default(); + headManager.getIsSsr = ()=>{ + return router.isSsr; + }; + appElement = document.getElementById("__next"); + return { + assetPrefix: prefix + }; + }); + return _initialize.apply(this, arguments); +} +function renderApp(App, appProps) { + return /*#__PURE__*/ _react.default.createElement(App, Object.assign({}, appProps)); +} +function AppContainer(param) { + let { children } = param; + var _autoExport; + return /*#__PURE__*/ _react.default.createElement(Container, { + fn: (error)=>// eslint-disable-next-line @typescript-eslint/no-use-before-define + renderError({ + App: CachedApp, + err: error + }).catch((err)=>console.error("Error rendering page: ", err)) + }, /*#__PURE__*/ _react.default.createElement(_appRouterContext.AppRouterContext.Provider, { + value: (0, _adapters).adaptForAppRouterInstance(router) + }, /*#__PURE__*/ _react.default.createElement(_hooksClientContext.SearchParamsContext.Provider, { + value: (0, _adapters).adaptForSearchParams(router) + }, /*#__PURE__*/ _react.default.createElement(_adapters.PathnameContextProviderAdapter, { + router: router, + isAutoExport: (_autoExport = self.__NEXT_DATA__.autoExport) != null ? _autoExport : false + }, /*#__PURE__*/ _react.default.createElement(_routerContext.RouterContext.Provider, { + value: (0, _router).makePublicRouterInstance(router) + }, /*#__PURE__*/ _react.default.createElement(_headManagerContext.HeadManagerContext.Provider, { + value: headManager + }, /*#__PURE__*/ _react.default.createElement(_imageConfigContext.ImageConfigContext.Provider, { + value: {"deviceSizes":[640,750,828,1080,1200,1920,2048,3840],"imageSizes":[16,32,48,64,96,128,256,384],"path":"/_next/image","loader":"default","dangerouslyAllowSVG":false,"unoptimized":false} + }, children))))))); +} +const wrapApp = (App)=>(wrappedAppProps)=>{ + const appProps = _extends({}, wrappedAppProps, { + Component: CachedComponent, + err: initialData.err, + router + }); + return /*#__PURE__*/ _react.default.createElement(AppContainer, null, renderApp(App, appProps)); + }; +// This method handles all runtime and debug errors. +// 404 and 500 errors are special kind of errors +// and they are still handle via the main render method. +function renderError(renderErrorProps) { + let { App , err } = renderErrorProps; + // In development runtime errors are caught by our overlay + // In production we catch runtime errors using componentDidCatch which will trigger renderError + if (false) {} + // Make sure we log the error to the console, otherwise users can't track down issues. + console.error(err); + console.error("A client-side exception has occurred, see here for more info: https://nextjs.org/docs/messages/client-side-exception-occurred"); + return pageLoader.loadPage("/_error").then((param)=>{ + let { page: ErrorComponent , styleSheets } = param; + return (lastAppProps == null ? void 0 : lastAppProps.Component) === ErrorComponent ? Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(__webpack_require__(67))).then((errorModule)=>{ + return Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(__webpack_require__(4297))).then((appModule)=>{ + App = appModule.default; + renderErrorProps.App = App; + return errorModule; + }); + }).then((m)=>({ + ErrorComponent: m.default, + styleSheets: [] + })) : { + ErrorComponent, + styleSheets + }; + }).then((param)=>{ + let { ErrorComponent , styleSheets } = param; + var ref; + // In production we do a normal render with the `ErrorComponent` as component. + // If we've gotten here upon initial render, we can use the props from the server. + // Otherwise, we need to call `getInitialProps` on `App` before mounting. + const AppTree = wrapApp(App); + const appCtx = { + Component: ErrorComponent, + AppTree, + router, + ctx: { + err, + pathname: initialData.page, + query: initialData.query, + asPath, + AppTree + } + }; + return Promise.resolve(((ref = renderErrorProps.props) == null ? void 0 : ref.err) ? renderErrorProps.props : (0, _utils).loadGetInitialProps(App, appCtx)).then((initProps)=>// eslint-disable-next-line @typescript-eslint/no-use-before-define + doRender(_extends({}, renderErrorProps, { + err, + Component: ErrorComponent, + styleSheets, + props: initProps + }))); + }); +} +// Dummy component that we render as a child of Root so that we can +// toggle the correct styles before the page is rendered. +function Head(param) { + let { callback } = param; + // We use `useLayoutEffect` to guarantee the callback is executed + // as soon as React flushes the update. + _react.default.useLayoutEffect(()=>callback(), [ + callback + ]); + return null; +} +let reactRoot = null; +// On initial render a hydrate should always happen +let shouldHydrate = true; +function clearMarks() { + [ + "beforeRender", + "afterHydrate", + "afterRender", + "routeChange" + ].forEach((mark)=>performance.clearMarks(mark)); +} +function markHydrateComplete() { + if (!_utils.ST) return; + performance.mark("afterHydrate") // mark end of hydration + ; + performance.measure("Next.js-before-hydration", "navigationStart", "beforeRender"); + performance.measure("Next.js-hydration", "beforeRender", "afterHydrate"); + if (onPerfEntry) { + performance.getEntriesByName("Next.js-hydration").forEach(onPerfEntry); + } + clearMarks(); +} +function markRenderComplete() { + if (!_utils.ST) return; + performance.mark("afterRender") // mark end of render + ; + const navStartEntries = performance.getEntriesByName("routeChange", "mark"); + if (!navStartEntries.length) return; + performance.measure("Next.js-route-change-to-render", navStartEntries[0].name, "beforeRender"); + performance.measure("Next.js-render", "beforeRender", "afterRender"); + if (onPerfEntry) { + performance.getEntriesByName("Next.js-render").forEach(onPerfEntry); + performance.getEntriesByName("Next.js-route-change-to-render").forEach(onPerfEntry); + } + clearMarks(); + [ + "Next.js-route-change-to-render", + "Next.js-render" + ].forEach((measure)=>performance.clearMeasures(measure)); +} +function renderReactElement(domEl, fn) { + // mark start of hydrate/render + if (_utils.ST) { + performance.mark("beforeRender"); + } + const reactEl = fn(shouldHydrate ? markHydrateComplete : markRenderComplete); + if (!reactRoot) { + // Unlike with createRoot, you don't need a separate root.render() call here + reactRoot = _client.default.hydrateRoot(domEl, reactEl); + // TODO: Remove shouldHydrate variable when React 18 is stable as it can depend on `reactRoot` existing + shouldHydrate = false; + } else { + const startTransition = _react.default.startTransition; + startTransition(()=>{ + reactRoot.render(reactEl); + }); + } +} +function Root(param) { + let { callbacks , children } = param; + // We use `useLayoutEffect` to guarantee the callbacks are executed + // as soon as React flushes the update + _react.default.useLayoutEffect(()=>callbacks.forEach((callback)=>callback()), [ + callbacks + ]); + // We should ask to measure the Web Vitals after rendering completes so we + // don't cause any hydration delay: + _react.default.useEffect(()=>{ + (0, _performanceRelayer).default(onPerfEntry); + }, []); + if (false) {} + return children; +} +function doRender(input) { + let { App , Component , props , err } = input; + let styleSheets = "initial" in input ? undefined : input.styleSheets; + Component = Component || lastAppProps.Component; + props = props || lastAppProps.props; + const appProps = _extends({}, props, { + Component, + err, + router + }); + // lastAppProps has to be set before ReactDom.render to account for ReactDom throwing an error. + lastAppProps = appProps; + let canceled = false; + let resolvePromise; + const renderPromise = new Promise((resolve, reject)=>{ + if (lastRenderReject) { + lastRenderReject(); + } + resolvePromise = ()=>{ + lastRenderReject = null; + resolve(); + }; + lastRenderReject = ()=>{ + canceled = true; + lastRenderReject = null; + const error = new Error("Cancel rendering route"); + error.cancelled = true; + reject(error); + }; + }); + // This function has a return type to ensure it doesn't start returning a + // Promise. It should remain synchronous. + function onStart() { + if (!styleSheets || // We use `style-loader` in development, so we don't need to do anything + // unless we're in production: + "production" !== "production") { + return false; + } + const currentStyleTags = looseToArray(document.querySelectorAll("style[data-n-href]")); + const currentHrefs = new Set(currentStyleTags.map((tag)=>tag.getAttribute("data-n-href"))); + const noscript = document.querySelector("noscript[data-n-css]"); + const nonce = noscript == null ? void 0 : noscript.getAttribute("data-n-css"); + styleSheets.forEach((param)=>{ + let { href , text } = param; + if (!currentHrefs.has(href)) { + const styleTag = document.createElement("style"); + styleTag.setAttribute("data-n-href", href); + styleTag.setAttribute("media", "x"); + if (nonce) { + styleTag.setAttribute("nonce", nonce); + } + document.head.appendChild(styleTag); + styleTag.appendChild(document.createTextNode(text)); + } + }); + return true; + } + function onHeadCommit() { + if (// unless we're in production: + true && // We can skip this during hydration. Running it wont cause any harm, but + // we may as well save the CPU cycles: + styleSheets && // Ensure this render was not canceled + !canceled) { + const desiredHrefs = new Set(styleSheets.map((s)=>s.href)); + const currentStyleTags = looseToArray(document.querySelectorAll("style[data-n-href]")); + const currentHrefs = currentStyleTags.map((tag)=>tag.getAttribute("data-n-href")); + // Toggle `